koreth@panarthea.ebay.sun.com (Steven Grimm) (10/25/89)
Submitted-by: ncar.ucar.edu!dunike!onecom!wldrdg!hans (Johann Ruegg) Posting-number: Volume 2, Issue 92 Archive-name: sozobon1.2/part01 Here is part 1 of the Sozobon 1.2 release. This is an intermediate release that only includes the compiler "hcc.ttp" and the optimizer "top.ttp". The compiler has bug fixes and some minor preprocessor enhancements. The optimizer is improved with a "registerizing" pass. Johann Ruegg ncar!dunike!onecom!wldrdg!hans #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 1 (of 9)." # Contents: hcc hcc/BSTOK.H hcc/COOKIE.H hcc/FLAGS.H hcc/GEN.H # hcc/MAKEFILE hcc/OPS.H hcc/PARAM.H hcc/STTOK.H hcc/SUBS_TOS.S # hcc/TOK.H hcc/TOS.LD hcc/TYTOK.H top top/HEALTH.C top/INST.H # top/IO.C top/MAIN.C top/MAKEFILE top/OPCODES.C top/OPCODES.H # top/SYM.C top/TOP.H top/UTIL.C # Wrapped by koreth@panarthea on Tue Oct 24 18:40:44 1989 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test ! -d 'hcc' ; then echo shar: Creating directory \"'hcc'\" mkdir 'hcc' fi if test -f 'hcc/BSTOK.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/BSTOK.H'\" else echo shar: Extracting \"'hcc/BSTOK.H'\" \(1464 characters\) sed "s/^X//" >'hcc/BSTOK.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * bstok.h X * X * basic token values X * (some compilers cant do enums, so use defines) X */ X X#ifndef ENUMS X#define BADTOK 0 X#define ID 1 X#define ICON 2 X#define FCON 3 X#define SCON 4 X#define DPARAM 6 /* parameter to #define */ X#define EOFTOK 7 X#define POSTINC 8 /* DOUBLE '+' is pre-inc */ X#define POSTDEC 9 /* DOUBLE '-' is pre-dec */ X#define TCONV 10 /* coertion */ X#define TSIZEOF 11 /* sizeof(type expr) */ X#define NL 12 X#define WS 13 /* white space */ X#define SCON2 14 /* <string> */ X#define PTRDIFF 0x18 X#define PTRADD 0x19 X#define PTRSUB 0x1a X#define ARROW 0x1b X#define LTEQ 0x1c X#define GTEQ 0x1d X#define NOTEQ 0x1e X#else Xenum { X BADTOK, ID, ICON, FCON, SCON, DPARAM, EOFTOK, X POSTINC, POSTDEC, TCONV, TSIZEOF, NL, WS, SCON2, X PTRDIFF, PTRADD, PTRSUB, ARROW, LTEQ, GTEQ, NOTEQ X}; X#endif X X#define ASSIGN 0x100+ /* add to char of op */ X#define DOUBLE 0x80+ X#define UNARY 0x200+ X X#define STAR (UNARY '*') /* used a lot */ X X#define isassign(x) (x >= 0x100) END_OF_FILE if test 1464 -ne `wc -c <'hcc/BSTOK.H'`; then echo shar: \"'hcc/BSTOK.H'\" unpacked with wrong size! fi # end of 'hcc/BSTOK.H' fi if test -f 'hcc/COOKIE.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/COOKIE.H'\" else echo shar: Extracting \"'hcc/COOKIE.H'\" \(1088 characters\) sed "s/^X//" >'hcc/COOKIE.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * cookie.h X */ X X/* restrictions on type */ X X#define R_INTEGRAL 1 X#define R_FLOATING 2 X#define R_POINTER 4 X#define R_STRUCT 8 X#define R_ARITH (R_INTEGRAL|R_FLOATING) X#define R_SCALAR (R_ARITH|R_POINTER) X#define R_ASSN (R_SCALAR|R_STRUCT) X X/* cookies */ X#define FORSIDE 1 X#define FORPUSH 2 X#define FORCC 3 X#define FORIMA 4 X#define FORADR 5 X#define FORINIT 6 X#define IND0 7 X#define RETSTRU 8 X X/* eval flags derived from cookie */ X#define NOVAL_OK 1 /* value is optional */ X#define CC_OK 2 /* just setting cond. codes okay */ X#define IMMA_OK 4 /* immediate OREG is okay */ END_OF_FILE if test 1088 -ne `wc -c <'hcc/COOKIE.H'`; then echo shar: \"'hcc/COOKIE.H'\" unpacked with wrong size! fi # end of 'hcc/COOKIE.H' fi if test -f 'hcc/FLAGS.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/FLAGS.H'\" else echo shar: Extracting \"'hcc/FLAGS.H'\" \(1138 characters\) sed "s/^X//" >'hcc/FLAGS.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * flags.h X * X * token or e_flags flags X */ X X#define CAN_U 2 /* can be unary op */ X#define CAN_AS 4 /* can be op-assign */ X#define SPECIAL 8 /* special token beginner ("'/*) */ X#define SEE_U 0x10 /* for ICON */ X#define SEE_L 0x20 /* for ICON */ X#define C_NOT_A 0x40 /* commutative but not associative */ X#define C_AND_A 0x80 /* commutative and associative */ X#define IMMEDID 0x100 /* Ptr to XXX ID which is really X Array of XXX or Fun ret XXX */ X#define CHILDNM 0x200 /* my name is my (left) child's name */ X#define SIDE_CC 0x400 /* cc set as side effect of op. */ X#define RCHILDNM 0x800 /* my name is my (right) child's name */ END_OF_FILE if test 1138 -ne `wc -c <'hcc/FLAGS.H'`; then echo shar: \"'hcc/FLAGS.H'\" unpacked with wrong size! fi # end of 'hcc/FLAGS.H' fi if test -f 'hcc/GEN.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/GEN.H'\" else echo shar: Extracting \"'hcc/GEN.H'\" \(1400 characters\) sed "s/^X//" >'hcc/GEN.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * gen.h X */ X X#include "cookie.h" X X/* parameters for case */ X#define C_SIMPLE 8 /* use simple if n <= this */ X#define C_RATIO 3 /* use table if max-min/n <= this */ X X/* branch types */ X/* designed so that pairs (i,i+1) with odd i represent opposites */ X#define B_EQ 1 X#define B_NE 2 X#define B_LT 3 X#define B_GE 4 X#define B_LE 5 X#define B_GT 6 X#define B_YES 7 X#define B_NO 8 X#define B_ULT 9 X#define B_UGE 10 X#define B_ULE 11 X#define B_UGT 12 X X/* derived nodes */ X/* re-use stmt keywords for now */ X#ifndef ENUMS X#define ONAME 'a' X#define OREG 'b' X#define REGVAR 'c' X#define PUSHER 'd' X#define CMPBR 'e' X#define FIELDAS 'f' X#else Xenum { X ONAME = 'a', OREG, REGVAR, PUSHER, CMPBR, FIELDAS X}; X#endif X X#define BR_TOK 'i' X X/* evaluation order values */ X#define EV_NONE 0 X#define EV_LEFT 1 X#define EV_RIGHT 2 X#define EV_LR 3 X#define EV_RL 4 X#define EV_LRSEP 5 /* left then right, but seperate */ END_OF_FILE if test 1400 -ne `wc -c <'hcc/GEN.H'`; then echo shar: \"'hcc/GEN.H'\" unpacked with wrong size! fi # end of 'hcc/GEN.H' fi if test -f 'hcc/MAKEFILE' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/MAKEFILE'\" else echo shar: Extracting \"'hcc/MAKEFILE'\" \(359 characters\) sed "s/^X//" >'hcc/MAKEFILE' <<'END_OF_FILE' X#RM=rm XCC=cc XLD=ld XAS=jas X XOBJS = d2.o decl.o expr.o fix.o fun.o g2.o gen.o gsub.o gunk.o \ X main.o md.o nodes.o out_st.o p2.o pre.o tok.o subs_tos.o X XH = bstok.h cookie.h flags.h gen.h nodes.h ops.h param.h \ X sttok.h tok.h tytok.h X XCFLAGS = -v -O X Xnhcc.ttp: $(OBJS) X ld -vpb -f tos.ld -o nhcc.ttp X X$(OBJS) : $(H) X Xclean: X $(RM) *.o X Xclobber: X $(RM) *.o hcc END_OF_FILE if test 359 -ne `wc -c <'hcc/MAKEFILE'`; then echo shar: \"'hcc/MAKEFILE'\" unpacked with wrong size! fi # end of 'hcc/MAKEFILE' fi if test -f 'hcc/OPS.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/OPS.H'\" else echo shar: Extracting \"'hcc/OPS.H'\" \(1058 characters\) sed "s/^X//" >'hcc/OPS.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * ops.h X * X * defines of allowed operands X * 'E' means Dreg or OREG or ONAME or (if on left) ICON X * 'Q' means ICON which is 1 to 8 X * ONE means ICON which is 1 X */ X X#define DOPD 1 X#define AOPD 2 X#define MOPD 4 X#define IOPD 8 X X#define DOPA 0x10 X#define AOPA 0x20 X#define MOPA 0x40 X#define IOPA 0x80 X X#define DOPM 0x100 X#define AOPM 0x200 X#define MOPM 0x400 X#define IOPM 0x800 X X#define QOPD 0x1000 X#define ONEOPM 0x2000 X#define ASSOC 0x4000 X X#define EOPD (DOPD|MOPD|IOPD) X#define DOPE (DOPD|DOPM) X#define IOPE (IOPD|IOPM) X#define EOPA (DOPA|MOPA|IOPA) END_OF_FILE if test 1058 -ne `wc -c <'hcc/OPS.H'`; then echo shar: \"'hcc/OPS.H'\" unpacked with wrong size! fi # end of 'hcc/OPS.H' fi if test -f 'hcc/PARAM.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/PARAM.H'\" else echo shar: Extracting \"'hcc/PARAM.H'\" \(2330 characters\) sed "s/^X//" >'hcc/PARAM.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * param.h X * X * basic parameters X */ X X#ifndef MMCC X#define MMCC 0 X#endif X X#ifndef CC68 X#define CC68 0 X#endif X X#ifndef dLibs X#define dLibs 0 X#endif X X#undef NULL X#define NULL 0L X X#ifndef LAT_HOST X#ifndef ACK_HOST X#define ENUMS 1 /* define if host compiler can do enums */ X#endif X#endif X X#define DEBUG 1 X X#define NHASH 32 X X#define ROPEN "r" X#define WOPEN "w" X#define FLTFORM "%.3g" X X#define MAXSTR 256 X#define MAXINCL 10 X#define NMSIZE 12 /* must be at least 12 */ X#define NMXSIZE 32 X X/* sizes of basic types */ X#ifndef NOLONGS X#define SIZE_C 1 /* char */ X#define SIZE_I 2 /* int */ X#define SIZE_S 2 /* short */ X#define SIZE_L 4 /* long */ X#define SIZE_U 2 /* unsigned */ X#define SIZE_F 4 /* float */ X#define SIZE_D 4 /* double */ X#define SIZE_P 4 /* pointer */ X#define MAXINT 0x7fffL X#define MININT -0x8000L X#define MAXUNS 0xffffL X#else X#define SIZE_C 1 /* char */ X#define SIZE_I 4 /* int */ X#define SIZE_S 2 /* short */ X#define SIZE_L 4 /* long */ X#define SIZE_U 4 /* unsigned */ X#define SIZE_F 4 /* float */ X#define SIZE_D 4 /* double */ X#define SIZE_P 4 /* pointer */ X#define MAXINT 0x7fffffff X#endif X X/* alignment requirements */ X#define ALN_C 0 /* char */ X#define ALN_I 1 /* int */ X#define ALN_S 1 /* short */ X#define ALN_L 1 /* long */ X#define ALN_U 1 /* unsigned */ X#define ALN_F 1 /* float */ X#define ALN_D 1 /* double */ X#define ALN_P 1 /* pointer */ X X#define STACKALN 1 X X/* usage for registers */ X#ifndef OUT_AZ X#define DRV_START 3 X#define DRV_END 7 X#define AREG 8 X#define ARV_START AREG+3 X#define ARV_END AREG+5 X#define FRAMEP AREG+6 X#else X#define DRV_START 4 X#define DRV_END 7 X#define AREG 8 X#define ARV_START AREG+3 X#define ARV_END AREG+4 X#define FRAMEP AREG+5 X#endif X X/* definition of stack frame */ X#define ARG_BASE 8 X#define LOC_BASE 0 X X/* need for own buffers (ALCYON hack ) ? */ X#define NEEDBUF 0 X END_OF_FILE if test 2330 -ne `wc -c <'hcc/PARAM.H'`; then echo shar: \"'hcc/PARAM.H'\" unpacked with wrong size! fi # end of 'hcc/PARAM.H' fi if test -f 'hcc/STTOK.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/STTOK.H'\" else echo shar: Extracting \"'hcc/STTOK.H'\" \(1009 characters\) sed "s/^X//" >'hcc/STTOK.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * sttok.h X * X * statement keyword tokens X */ X X#ifndef ENUMS X#define K_GOTO 'a' X#define K_RETURN 'b' X#define K_BREAK 'c' X#define K_CONTINUE 'd' X X#define K_IF 'e' X#define K_ELSE 'f' X#define K_FOR 'g' X#define K_DO 'h' X#define K_WHILE 'i' X#define K_SWITCH 'j' X X#define K_CASE 'k' X#define K_DEFAULT 'l' X#define K_ASM 'm' X X#define K_SIZEOF 'n' X X#else Xenum { X K_GOTO = 'a', K_RETURN, K_BREAK, K_CONTINUE, X K_IF, K_ELSE, K_FOR, K_DO, K_WHILE, K_SWITCH, X K_CASE, K_DEFAULT, K_ASM, X K_SIZEOF, X}; X#endif END_OF_FILE if test 1009 -ne `wc -c <'hcc/STTOK.H'`; then echo shar: \"'hcc/STTOK.H'\" unpacked with wrong size! fi # end of 'hcc/STTOK.H' fi if test -f 'hcc/SUBS_TOS.S' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/SUBS_TOS.S'\" else echo shar: Extracting \"'hcc/SUBS_TOS.S'\" \(492 characters\) sed "s/^X//" >'hcc/SUBS_TOS.S' <<'END_OF_FILE' X .globl _lclr X .text X_lclr: X link a6,#0 X X move.l 8(a6),a0 X move 12(a6),d0 X bra L5 XL4: X clr.l (a0)+ XL5: X dbf d0,L4 X X unlk a6 X rts X X .globl _lcpy X .text X_lcpy: X link a6,#0 X X move.l 8(a6),a0 X move.l 12(a6),a1 X move 16(a6),d0 X bra L8 XL7: X move.l (a1)+,(a0)+ XL8: X dbf d0,L7 X X unlk a6 X rts X X .data X .globl _f_zero X_f_zero: X .dc.l 0 X .globl _f_ten X_f_ten: X .dc.l $a0000044 X .globl _f_tenth X_f_tenth: X .dc.l $cccccd3d X .globl _f_e10 X_f_e10: X .dc.l $9502f962 X .globl _f_em10 X_f_em10: X .dc.l $dbe6fd1f END_OF_FILE if test 492 -ne `wc -c <'hcc/SUBS_TOS.S'`; then echo shar: \"'hcc/SUBS_TOS.S'\" unpacked with wrong size! fi # end of 'hcc/SUBS_TOS.S' fi if test -f 'hcc/TOK.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/TOK.H'\" else echo shar: Extracting \"'hcc/TOK.H'\" \(1211 characters\) sed "s/^X//" >'hcc/TOK.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * tok.h X * X * establish token values X */ X Xstruct tok { X char *name; X int tnum; X long ival; X double fval; X char prec; X int flags; X}; X X#include "flags.h" X#include "bstok.h" X X#define is_sclass(x) (x >= K_EXTERN && x <= K_STATIC) X#define is_tadj(x) (x >= K_LONG && x <= K_UNSIGNED) X#define is_btype(x) (x >= K_INT && x <= K_VOID) X#define is_tykw(x) (x >= K_EXTERN && x <= K_STRUCT) X X#define is_stkw(x) (x >= K_GOTO && x <= K_ASM) X#define is_brast(x) (x >= K_GOTO && x <= K_CONTINUE) X#define is_blkst(x) (x >= K_IF && x <= K_SWITCH) X#define is_lblst(x) (x >= K_CASE && x <= K_DEFAULT) X X#include "tytok.h" X#include "sttok.h" X X/* modifier seen flags */ X#define SAW_SHORT 1 X#define SAW_LONG 2 X#define SAW_UNS 4 END_OF_FILE if test 1211 -ne `wc -c <'hcc/TOK.H'`; then echo shar: \"'hcc/TOK.H'\" unpacked with wrong size! fi # end of 'hcc/TOK.H' fi if test -f 'hcc/TOS.LD' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/TOS.LD'\" else echo shar: Extracting \"'hcc/TOS.LD'\" \(176 characters\) sed "s/^X//" >'hcc/TOS.LD' <<'END_OF_FILE' X\sozobon\lib\dstart.o Xd2.o decl.o expr.o fix.o fun.o g2.o gen.o gsub.o gunk.o Xmain.o md.o nodes.o out_st.o p2.o pre.o tok.o subs_tos.o X\sozobon\lib\libm.a \sozobon\lib\dlibs.a END_OF_FILE if test 176 -ne `wc -c <'hcc/TOS.LD'`; then echo shar: \"'hcc/TOS.LD'\" unpacked with wrong size! fi # end of 'hcc/TOS.LD' fi if test -f 'hcc/TYTOK.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'hcc/TYTOK.H'\" else echo shar: Extracting \"'hcc/TYTOK.H'\" \(1490 characters\) sed "s/^X//" >'hcc/TYTOK.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Johann Ruegg X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X * X * tytok.h X * X * keyword token values X */ X X#ifndef ENUMS X#define K_EXTERN 'A' X#define K_AUTO 'B' X#define K_REGISTER 'C' X#define K_TYPEDEF 'D' X#define K_STATIC 'E' X X#define ENUM_SC K_STATIC+1 /* storage class for enum item */ X#define HERE_SC K_STATIC+2 /* storage class for glb def */ X#define FIRST_SC K_EXTERN X#define LAST_SC K_STATIC X X#define T_UCHAR 'F' X#define T_ULONG 'G' X X#define K_LONG 'H' X#define K_SHORT 'I' X#define K_UNSIGNED 'J' X X#define K_INT 'K' X#define K_CHAR 'L' X#define K_FLOAT 'M' X#define K_DOUBLE 'N' X#define K_VOID 'O' X X#define FIRST_BAS T_UCHAR X#define LAST_BAS K_VOID X X#define K_UNION 'P' X#define K_ENUM 'Q' X#define K_STRUCT 'R' X#else X#define FIRST_SC K_EXTERN X#define LAST_SC K_STATIC X#define FIRST_BAS T_UCHAR X#define LAST_BAS K_VOID Xenum { X K_EXTERN = 'A', K_AUTO, K_REGISTER, K_TYPEDEF, K_STATIC, X ENUM_SC, HERE_SC, X T_UCHAR, T_ULONG, X K_LONG, K_SHORT, K_UNSIGNED, X K_INT, K_CHAR, K_FLOAT, K_DOUBLE, K_VOID, X K_UNION, K_ENUM, K_STRUCT X}; X#endif END_OF_FILE if test 1490 -ne `wc -c <'hcc/TYTOK.H'`; then echo shar: \"'hcc/TYTOK.H'\" unpacked with wrong size! fi # end of 'hcc/TYTOK.H' fi if test ! -d 'top' ; then echo shar: Creating directory \"'top'\" mkdir 'top' fi if test -f 'top/HEALTH.C' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/HEALTH.C'\" else echo shar: Extracting \"'top/HEALTH.C'\" \(3765 characters\) sed "s/^X//" >'top/HEALTH.C' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X X/* X * Routines for data flow analysis by block and function. X */ X X#include "top.h" X X/* X * bprep() - initial analysis of a block X */ Xvoid Xbprep(bp) XBLOCK *bp; X{ X register INST *ip; X register int ref, set; X X ref = set = 0; X for (ip = bp->first; ip != NULL ;ip = ip->next) { X ref |= (ip->rref = reg_ref(ip)) & ~set; X set |= (ip->rset = reg_set(ip)); X } X bp->rref = ref; X bp->rset = set; X} X X/* X * fprep() - perform initial analysis of individual blocks in a function X */ Xstatic void Xfprep(bp) XBLOCK *bp; X{ X register BLOCK *cp; X X for (cp = bp; cp != NULL ;cp = cp->next) X bprep(cp); X} X Xstatic bool Xscan_ref(bp, reg) Xregister BLOCK *bp; Xregister int reg; X{ X register INST *ip; X X if (bp == NULL) X return FALSE; X X if (bp->rref & reg) X return TRUE; X X if (bp->rset & reg) X return FALSE; X X if (bp->flags & B_MARK) X return FALSE; X X if (bp->flags & B_RET) X return FALSE; X X bp->flags |= B_MARK; X X if (scan_ref(bp->bcond, reg)) X return TRUE; X X if (scan_ref(bp->bfall, reg)) X return TRUE; X X for (ip = bp->first; ip != NULL ;ip = ip->next) { X if (ip->opcode == DC && (ip->flags & LENL)) { X BLOCK *db; X X if (is_astr(ip->src.amode) && (ip->src.astr != NULL) && X (db = getsym(ip->src.astr)) != NULL) X if (scan_ref(db, reg)) X return TRUE; X } X } X return FALSE; X} X X/* X * is_live(bp, reg) - is 'reg' live at the end of block 'bp' X * X * Look ahead through the traversal graph to see what might happen to the X * given register. If we can find any reachable block that references 'reg' X * before setting it, the register is live. Scanning stops when the register X * is set, we loop back to the starting block, or the function returns. X */ Xstatic bool Xis_live(bp, reg) Xregister BLOCK *bp; Xregister int reg; X{ X register INST *ip; X register BLOCK *cp; X X /* X * Clear all the mark bits X */ X for (cp = fhead; cp != NULL ;cp = cp->next) X cp->flags &= ~B_MARK; X X bp->flags |= B_MARK; X X if (scan_ref(bp->bfall, reg)) X return TRUE; X X if (scan_ref(bp->bcond, reg)) X return TRUE; X X for (ip = bp->first; ip != NULL ;ip = ip->next) { X if (ip->opcode == DC && (ip->flags & LENL)) { X BLOCK *db; X X if (is_astr(ip->src.amode) && (ip->src.astr != NULL) && X (db = getsym(ip->src.astr)) != NULL) X if (scan_ref(db, reg)) X return TRUE; X } X } X return FALSE; X} X X/* X * bflow() - live/dead analysis for a given block X * X * Work backward from the end of the block, checking the status of registers. X * To start with, figure out the state of each register as of the end of the X * block. Then work backward, checking registers only as necessary. X */ Xstatic void Xbflow(bp) XBLOCK *bp; X{ X register INST *ip; X register int live = 0; X register int reg; X X /* X * Figure out what's alive at the end of this block. X */ X for (reg = FIRSTREG; reg <= LASTREG ;reg++) { X if (is_live(bp, RM(reg))) X live |= RM(reg); X } X /* X * Now work through the instructions in the block. X */ X for (ip = bp->last; ip != NULL ;ip = ip->prev) { X ip->live = live; X X for (reg = FIRSTREG; reg <= LASTREG ;reg++) { X if (ip->rref & RM(reg)) X live |= RM(reg); X else if (ip->rset & RM(reg)) X live &= ~RM(reg); X } X } X} X Xvoid Xrhealth(bp, do_prep) XBLOCK *bp; Xbool do_prep; X{ X register BLOCK *cp; X X if (do_prep) X fprep(bp); X X for (cp = bp; cp != NULL ;cp = cp->next) X bflow(cp); X} END_OF_FILE if test 3765 -ne `wc -c <'top/HEALTH.C'`; then echo shar: \"'top/HEALTH.C'\" unpacked with wrong size! fi # end of 'top/HEALTH.C' fi if test -f 'top/INST.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/INST.H'\" else echo shar: Extracting \"'top/INST.H'\" \(2922 characters\) sed "s/^X//" >'top/INST.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X X/* X * Misc. define's, etc. for instruction parsing. X */ X Xstruct opnd { X unsigned char amode; /* addressing mode used */ X unsigned char areg; /* primary register */ X unsigned char ireg; /* index register, if applicable */ X union { X long i_disp; /* also used for immediate data */ X char *i_astr; /* pointer to any symbol present */ X } i_data; X}; X#define disp i_data.i_disp X#define astr i_data.i_astr X X/* X * is_astr(m) macro to determine, based on the amode field, whether X * the 'astr' field of the structure is active. X */ X#define is_astr(m) (((m) == ABS) || ((m) == (IMM|SYMB))) X X/* X * Addressing modes (in 'amode') X */ X#define NONE 0 /* operand unused */ X#define REG 1 /* register direct */ X#define IMM 2 /* immediate */ X#define ABS 3 /* absolute */ X#define REGI 4 /* reg. indirect */ X#define REGID 5 /* reg. indirect, w/ displacement */ X#define REGIDX 6 /* reg. indirect, w/ displacement & index */ X#define PCD 7 /* PC relative, w/ displacement */ X#define PCDX 8 /* PC relative, w/ displacement & index */ X X#define XLONG 0x10 /* long index register used */ X#define SYMB 0x20 /* symbol used, not constant */ X#define INC 0x40 /* auto-increment */ X#define DEC 0x80 /* auto-decrement */ X X#define MMASK 0x0f /* mode mask */ X#define FMASK 0xf0 /* flag mask */ X X#define M(x) ((x) & MMASK) X#define F(x) ((x) & FMASK) X X/* X * Registers X */ X X#define FIRSTREG 0 X#define A0 0 X#define A1 1 X#define A2 2 X#define A3 3 X#define A4 4 X#define A5 5 X#define A6 6 X#define A7 7 X#define SP 7 /* alias for A7 */ X#define D0 8 X#define D1 9 X#define D2 10 X#define D3 11 X#define D4 12 X#define D5 13 X#define D6 14 X#define D7 15 X#define LASTREG 15 X X#define ISD(x) ((x) >= D0 && (x) <= D7) /* is 'x' a D reg. */ X#define ISA(x) ((x) >= A0 && (x) <= A7) /* is 'x' an A reg. */ X#define RM(x) (1 << (x)) /* form a register mask */ X X/* X * DOK(x) - evaluates TRUE if 'x' is okay for a displacement value. X * X * 'x' must be of type "long" X */ X#define DOK(x) (((x) >= -32768L) && ((x) <= 32767L)) X X/* X * D8OK(x) - like DOK but for 8-bit displacements X */ X#define D8OK(x) (((x) >= -128) && ((x) <= 127)) X Xstruct inst { X char opcode; /* type of instruction */ X char flags; /* length, etc. */ X struct opnd src, dst; /* optional operands */ X int rref, rset; X int live; /* regs. live after this inst. */ X struct inst *next; X struct inst *prev; X}; X X/* X * Instruction flags X */ X X#define LENB 0x01 X#define LENW 0x02 X#define LENL 0x04 END_OF_FILE if test 2922 -ne `wc -c <'top/INST.H'`; then echo shar: \"'top/INST.H'\" unpacked with wrong size! fi # end of 'top/INST.H' fi if test -f 'top/IO.C' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/IO.C'\" else echo shar: Extracting \"'top/IO.C'\" \(2661 characters\) sed "s/^X//" >'top/IO.C' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X#include "top.h" X X/* X * Low-level i/o routines. X */ X X/* X * mode tells what kind of stuff we're reading at the moment. X */ Xstatic int mode; X X#define BSS 0 X#define DATA 1 X#define TEXT 2 X Xstatic char *mnames[] = { X ".bss", X ".data", X ".text" X}; X X/* X * Tokens from the current line... X */ Xchar *t_line; /* the entire line */ Xchar *t_lab; /* label, if any */ Xchar *t_op; /* opcode */ Xchar *t_arg; /* arguments */ X X#define ISWHITE(c) ((c) == '\t' || (c) == ' ' || (c) == '\n') X X#define LSIZE 2048 /* max. size of an input line */ X X/* X * readline() - read the next line from the file X * X * readline passes data and bss through to the output, only returning X * when a line of text has been read. Returns FALSE on end of file. X */ Xbool Xreadline() X{ X char *fgets(); X static void tokenize(); X static char buf[LSIZE]; X X /* X * Keep looping until we get a line of text X */ X for (;;) { X if (fgets(buf, LSIZE, ifp) == NULL) X return FALSE; X X t_line = buf; X X /* X * Find out if the mode is changing. X */ X tokenize(buf); X X /* X * If we see a "var" hint from the compiler, call addvar() X * to remember it for later use. X */ X if (t_lab[0] == ';') { X if (strcmp(t_lab, ";var") == 0) X addvar(atoi(t_op), atoi(t_arg)); X continue; X } X X if (t_op[0] == '.') { /* is it a pseudo-op? */ X if (strcmp(t_op, mnames[BSS]) == 0) X mode = BSS; X else if (strcmp(t_op, mnames[DATA]) == 0) X mode = DATA; X else if (strcmp(t_op, mnames[TEXT]) == 0) { X mode = TEXT; X continue; X } X } X if (mode == TEXT) X return TRUE; X else X fputs(buf, ofp); X } X} X Xstatic void Xtokenize(s) Xregister char *s; X{ X static char label[LSIZE], opcode[LSIZE], args[LSIZE]; X register int i; X X /* X * Grab the label, if any X */ X i = 0; X while (*s && !ISWHITE(*s) && *s != ':') X label[i++] = *s++; X label[i] = '\0'; X X if (*s == ':') X s++; X X while (ISWHITE(*s)) X s++; X X /* X * Grab the opcode X */ X i = 0; X while (*s && !ISWHITE(*s)) X opcode[i++] = *s++; X opcode[i] = '\0'; X X while (ISWHITE(*s)) X s++; X X /* X * Grab the arguments X */ X i = 0; X while (*s && !ISWHITE(*s)) X args[i++] = *s++; X args[i] = '\0'; X X t_lab = label; X t_op = opcode; X t_arg = args; X} END_OF_FILE if test 2661 -ne `wc -c <'top/IO.C'`; then echo shar: \"'top/IO.C'\" unpacked with wrong size! fi # end of 'top/IO.C' fi if test -f 'top/MAIN.C' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/MAIN.C'\" else echo shar: Extracting \"'top/MAIN.C'\" \(3815 characters\) sed "s/^X//" >'top/MAIN.C' <<'END_OF_FILE' X/* Copyright (c) 1988,1989 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X#include "top.h" X XFILE *ifp, *ofp; /* input/output file pointers */ X X#ifndef MINIX Xlong _STKSIZ = 32768L; /* need mucho stack for recursion */ X#endif X X/* X * Options X */ Xbool debug = FALSE; Xbool do_brev = TRUE; /* branch reversals enabled */ Xbool do_peep = TRUE; /* peephole optimizations enabled */ Xbool do_regs = TRUE; /* do "registerizing" */ Xbool do_lrot = TRUE; /* do loop rotations */ Xbool verbose = FALSE; X X/* X * Optimization statistics (use -v to print) X */ Xint s_bdel = 0; /* branches deleted */ Xint s_badd = 0; /* branches added */ Xint s_brev = 0; /* branch reversals */ Xint s_lrot = 0; /* loop rotations */ Xint s_peep1 = 0; /* 1 instruction peephole changes */ Xint s_peep2 = 0; /* 2 instruction peephole changes */ Xint s_peep3 = 0; /* 3 instruction peephole changes */ Xint s_idel = 0; /* instructions deleted */ Xint s_reg = 0; /* variables "registerized" */ X X#define TMPFILE "top_tmp.$$$" /* temporary file name */ Xint use_temp = FALSE; /* using temporary file */ X Xchar *Version = X"top Version 1.20 Copyright (c) 1988,1989 by Sozobon, Limited."; X Xusage() X{ X fprintf(stderr, "usage: top [-dvblpr] infile [outfile]\n"); X exit(1); X} X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X FILE *fopen(); X register char *s; X X while (argc > 1 && argv[1][0] == '-') { X for (s = &argv[1][1]; *s ;s++) { X switch (*s) { X case 'd': X debug = TRUE; X break; X case 'b': X do_brev = FALSE; X break; X case 'p': X do_peep = FALSE; X break; X case 'r': X do_regs = FALSE; X break; X case 'l': X do_lrot = FALSE; X break; X case 'v': X fprintf(stderr, "%s\n", Version); X verbose = TRUE; X break; X case 'O': X /* X * When options are received from 'cc' they X * look like "-Oxxx", so just ignore the 'O'. X */ X break; X default: X usage(); X break; X } X } X argv++; X argc--; X } X X if (argc > 3) X usage(); X X if (argc > 1) { X if (strcmp(argv[1], "-") == 0) X ifp = stdin; X else if ((ifp = fopen(argv[1], "r")) == NULL) { X fprintf(stderr, "top: can't open input file '%s'\n", X argv[1]); X exit(1); X } X if (argc > 2) { X if (strcmp(argv[2], "-") == 0) X ofp = stdout; X else if ((ofp = fopen(argv[2], "w")) == NULL) { X fprintf(stderr, "top: can't open output file '%s'\n", X argv[2]); X exit(1); X } X } else { X if ((ofp = fopen(TMPFILE, "w")) == NULL) { X fprintf(stderr, "top: can't create temp file\n"); X exit(1); X } X use_temp = TRUE; X } X } else X usage(); X X dofile(); X X if (verbose) { X if (do_peep) { X fprintf(stderr, "Peephole changes (1): %4d\n", s_peep1); X fprintf(stderr, "Peephole changes (2): %4d\n", s_peep2); X fprintf(stderr, "Peephole changes (3): %4d\n", s_peep3); X fprintf(stderr, "Instructions deleted: %4d\n", s_idel); X } X if (do_regs) X fprintf(stderr, "Variables registered: %4d\n", s_reg); X if (do_lrot) X fprintf(stderr, "Loop rotations : %4d\n", s_lrot); X if (do_brev) X fprintf(stderr, "Branch reversals : %4d\n", s_brev); X fprintf(stderr, "Branches removed : %4d\n", s_bdel - s_badd); X } X X /* X * If we're overwriting the original file, remove the old X * version, and rename the temp file to the old name. X */ X if (use_temp) { X remove(argv[1]); X rename(TMPFILE, argv[1]); X } X X exit(0); X} X Xdofile() X{ X if (!readline()) X return; X X while (dofunc()) X ; X} END_OF_FILE if test 3815 -ne `wc -c <'top/MAIN.C'`; then echo shar: \"'top/MAIN.C'\" unpacked with wrong size! fi # end of 'top/MAIN.C' fi if test -f 'top/MAKEFILE' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/MAKEFILE'\" else echo shar: Extracting \"'top/MAKEFILE'\" \(260 characters\) sed "s/^X//" >'top/MAKEFILE' <<'END_OF_FILE' X# X# Makefile for the optimizer X# XCC=cc X XOBJ = main.o io.o util.o sym.o func.o branch.o inst.o opcodes.o \ X health.o data.o peep1.o peep2.o peep3.o reg.o X XCFLAGS = -O X Xxtop.ttp : $(OBJ) X $(CC) $(OBJ) -o xtop.ttp X Xclean: X $(RM) *.o X Xclobber: X $(RM) *.o xtop.ttp END_OF_FILE if test 260 -ne `wc -c <'top/MAKEFILE'`; then echo shar: \"'top/MAKEFILE'\" unpacked with wrong size! fi # end of 'top/MAKEFILE' fi if test -f 'top/OPCODES.C' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/OPCODES.C'\" else echo shar: Extracting \"'top/OPCODES.C'\" \(1545 characters\) sed "s/^X//" >'top/OPCODES.C' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X X/* X * Mnemonics for the instructions. X */ X Xchar *opnames[] = { X "or", X "btst", X "movep", X "bchg", X "bclr", X "bset", X "and", X "sub", X "add", X "eor", X "cmp", X "move", X "negx", X "chk", X "lea", X "clr", X "neg", X "not", X "nbcd", X "swap", X "pea", X "ext", X "movem", X "tst", X "tas", X "trap", X "link", X "unlk", X "reset", X "nop", X "stop", X "rte", X "rts", X "trapv", X "rtr", X "jsr", X "jmp", X "addq", X "st", X "dbt", X "subq", X "sf", X "dbra", /* also dbf */ X "shi", X "dbhi", X "sls", X "dbls", X "scc", X "dbcc", X "scs", X "dbcs", X "sne", X "dbne", X "seq", X "dbeq", X "svc", X "dvc", X "svs", X "dvs", X "spl", X "smi", X "dbmi", X "sge", X "dbge", X "slt", X "dblt", X "sgt", X "dbgt", X "sle", X "dble", X "bra", X "bsr", X "bhi", X "bls", X "bcc", X "bcs", X "bne", X "beq", X "bvc", X "bvs", X "bpl", X "bmi", X "bge", X "blt", X "bgt", X "ble", X "moveq", X "divu", X "sbcd", X "divs", X "subx", X "cmpm", X "mulu", X "abcd", X "exg", X "muls", X "addx", X "asr", X "lsr", X "roxr", X "ror", X "asl", X "lsl", X "roxl", X "rol", X/* X * Pseudo-ops that show up in text sections X */ X ".dc", X (char *) 0 X}; END_OF_FILE if test 1545 -ne `wc -c <'top/OPCODES.C'`; then echo shar: \"'top/OPCODES.C'\" unpacked with wrong size! fi # end of 'top/OPCODES.C' fi if test -f 'top/OPCODES.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/OPCODES.H'\" else echo shar: Extracting \"'top/OPCODES.H'\" \(2212 characters\) sed "s/^X//" >'top/OPCODES.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X X/* X * Defines for the instructions X */ X X#define OR 0 X#define BTST 1 X#define MOVEP 2 X#define BCHG 3 X#define BCLR 4 X#define BSET 5 X#define AND 6 X#define SUB 7 X#define ADD 8 X#define EOR 9 X#define CMP 10 X#define MOVE 11 X#define NEGX 12 X#define CHK 13 X#define LEA 14 X#define CLR 15 X#define NEG 16 X#define NOT 17 X#define NBCD 18 X#define SWAP 19 X#define PEA 20 X#define EXT 21 X#define MOVEM 22 X#define TST 23 X#define TAS 24 X#define TRAP 25 X#define LINK 26 X#define UNLK 27 X#define RESET 28 X#define NOP 29 X#define STOP 30 X#define RTE 31 X#define RTS 32 X#define TRAPV 33 X#define RTR 34 X#define JSR 35 X#define JMP 36 X#define ADDQ 37 X#define ST 38 X#define DBT 39 X#define SUBQ 40 X#define SF 41 X#define DBRA 42 /* aka DBF */ X#define SHI 43 X#define DBHI 44 X#define SLS 45 X#define DBLS 46 X#define SCC 47 X#define DBCC 48 X#define SCS 49 X#define DBCS 50 X#define SNE 51 X#define DBNE 52 X#define SEQ 53 X#define DBEQ 54 X#define SVC 55 X#define DVC 56 X#define SVS 57 X#define DVS 58 X#define SPL 59 X#define SMI 60 X#define DBMI 61 X#define SGE 62 X#define DBGE 63 X#define SLT 64 X#define DBLT 65 X#define SGT 66 X#define DBGT 67 X#define SLE 68 X#define DBLE 69 X#define BRA 70 X#define BSR 71 X#define BHI 72 X#define BLS 73 X#define BCC 74 X#define BCS 75 X#define BNE 76 X#define BEQ 77 X#define BVC 78 X#define BVS 79 X#define BPL 80 X#define BMI 81 X#define BGE 82 X#define BLT 83 X#define BGT 84 X#define BLE 85 X#define MOVEQ 86 X#define DIVU 87 X#define SBCD 88 X#define DIVS 89 X#define SUBX 90 X#define CMPM 91 X#define MULU 92 X#define ABCD 93 X#define EXG 94 X#define MULS 95 X#define ADDX 96 X#define ASR 97 X#define LSR 98 X#define ROXR 99 X#define ROR 100 X#define ASL 101 X#define LSL 102 X#define ROXL 103 X#define ROL 104 X/* X * Pseudo-ops X */ X#define DC 105 END_OF_FILE if test 2212 -ne `wc -c <'top/OPCODES.H'`; then echo shar: \"'top/OPCODES.H'\" unpacked with wrong size! fi # end of 'top/OPCODES.H' fi if test -f 'top/SYM.C' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/SYM.C'\" else echo shar: Extracting \"'top/SYM.C'\" \(3184 characters\) sed "s/^X//" >'top/SYM.C' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X#include "top.h" X X/* X * Symbol table: X * X * For each symbol, contains a pointer to the block starting at the X * given symbol, and a pointer to the next symbol in the symbol table. X */ Xstruct sym { X char *name; X BLOCK *bp; X struct sym *next; X}; X Xstruct sym *sfirst = NULL; Xstruct sym *slast = NULL; X X/* X * newblock(name) - allocate a new block structure and initialize it X */ XBLOCK * Xnewblock(name) Xregister char *name; X{ X register BLOCK *bp; X X if ((bp = (BLOCK *) alloc(sizeof(BLOCK))) == NULL) X return NULL; X X /* X * Initialize the allocated block structure. X */ X X if ((bp->name = strsave(name)) == NULL) { X free(bp); X return NULL; X } X X bp->flags = 0; X bp->ref = 0; X bp->bcode = 0; X bp->first = NULL; X bp->last = NULL; X bp->bcond = NULL; X bp->bfall = NULL; X bp->chain = NULL; X bp->next = NULL; X bp->rref = bp->rset = 0; X X return bp; X} X X/* X * mksym(name) - make a new symbol table entry X * X * mksym creates new symbol table entries, and allocates space for the X * 'block' structure that will be used for the symbol. This can happen X * when a reference to a block is detected, but before the block has X * been encountered. Since we allocate the block structure here, other X * blocks can reference it before we actually read it in. X */ XBLOCK * Xmksym(name) Xregister char *name; X{ X register struct sym *new; X X if ((new = (struct sym *) alloc(sizeof(struct sym))) == NULL) X return NULL; X X if ((new->bp = newblock(name)) == NULL) { X free(new); X return NULL; X } X X new->name = new->bp->name; X new->next = NULL; X X if (sfirst == NULL) X sfirst = slast = new; X else { X slast->next = new; X slast = new; X } X X return new->bp; X} X X/* X * getsym(name) - return a pointer to the block for symbol 'name' X * X * Scans the symbol table for the given symbol and returns a pointer X * to its block, when found, or NULL if not present. X */ XBLOCK * Xgetsym(name) Xregister char *name; X{ X register struct sym *sp; X X for (sp = sfirst; sp != NULL ;sp = sp->next) { X if (strcmp(sp->name, name) == 0) X return sp->bp; X } X return NULL; X} X X/* X * freeop() - free an operand X */ Xvoid Xfreeop(op) Xstruct opnd *op; X{ X if (is_astr(op->amode) && op->astr != NULL) X free(op->astr); X} X X/* X * freesym() - free all symbol table space X */ Xvoid Xfreesym() X{ X register struct sym *sp, *nexts; X register INST *ip, *nexti; X X for (sp = sfirst; sp != NULL ;sp = nexts) { X nexts = sp->next; X for (ip = sp->bp->first; ip != NULL ; ip = nexti) { X nexti = ip->next; X X freeop(&ip->src); X freeop(&ip->dst); X free(ip); X } X free(sp->name); X free(sp->bp); X free(sp); X } X sfirst = slast = NULL; X} X Xchar * Xmktmp() X{ X static char tname[32]; X static int tnum = 0; X X sprintf(tname, "T%d", tnum++); X X return tname; X} END_OF_FILE if test 3184 -ne `wc -c <'top/SYM.C'`; then echo shar: \"'top/SYM.C'\" unpacked with wrong size! fi # end of 'top/SYM.C' fi if test -f 'top/TOP.H' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/TOP.H'\" else echo shar: Extracting \"'top/TOP.H'\" \(3752 characters\) sed "s/^X//" >'top/TOP.H' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X X#include <stdio.h> X#include <ctype.h> X X#include "inst.h" X#include "opcodes.h" X X/* #define DEBUG /* enable debug code */ X X#ifdef DEBUG X#define DBG(x) if (debug) { x; } X#else X#define DBG(x) X#endif X X#ifndef void X#define void int X#endif X X/* X * Basic defines and declarations for the optimizer. X */ X Xtypedef int bool; X X#ifndef FALSE X#define FALSE 0 X#define TRUE 1 X#endif X X/* X * Basic Block: X * X * References a linked list of instructions that make up the block. X * Each block can be exited via one of two branches, which are X * represented by pointers to two other blocks, or null. X */ Xstruct block { X int flags; /* flags relating to this block */ X int ref; /* # of references to this block */ X int bcode; /* type of exiting branch */ X char *name; /* symbol name that starts the block */ X X struct inst *first, /* first instruction in block */ X *last; /* last instruction in block */ X X /* X * Execution traversals X */ X struct block *bcond, /* conditional branch (or NULL) */ X *bfall; /* "fall through" branch */ X X /* X * Logical traversals X */ X struct block *chain; /* links all blocks together */ X struct block *next; /* next block in the file */ X X /* X * Information for data-flow analysis X */ X int rref; /* registers ref'd before set */ X int rset; /* registers modified by block */ X}; X Xtypedef struct block BLOCK; Xtypedef struct inst INST; X X/* X * Block flags X */ X X#define B_GLOBAL 0x01 /* is the block's symbol global? */ X#define B_TOUCHED 0x02 /* used in traversals */ X#define B_LABEL 0x04 /* the block needs a label */ X#define B_ISREACHED 0x08 /* block IS reached (for switches) */ X#define B_RET 0x10 /* block terminates with a 'return' */ X#define B_MARK 0x20 /* temporary 'touched' mark */ X X/* X * Global data X */ X Xextern FILE *ifp, *ofp; /* input and output file pointers */ X X/* X * Option flags set in main X */ Xextern bool debug; Xextern bool do_peep; /* enable peephole opt. */ Xextern bool do_brev; /* enable branch reversals */ Xextern bool do_regs; /* enable "registerizing" */ Xextern bool do_lrot; /* enable loop rotations */ Xextern bool verbose; X X/* X * Optimization stats X */ Xextern int s_bdel; Xextern int s_badd; Xextern int s_brev; Xextern int s_peep1; Xextern int s_peep2; Xextern int s_peep3; Xextern int s_idel; Xextern int s_reg; Xextern int s_lrot; X X/* X * These are set after calling readline. X */ Xextern char *t_line; /* text of the last line */ Xextern char *t_lab; /* label (if any) on the last line */ Xextern char *t_op; /* opcode */ Xextern char *t_arg; /* arguments */ X X Xextern char *opnames[]; /* mnemonics for the instructions */ X Xextern BLOCK *fhead; /* head of the current function */ X X/* X * Function declarations X */ X X/* X * branch.c X */ Xextern void bopt(); X X/* X * data.c X */ Xextern int reg_ref(), reg_set(); Xextern bool sets(), refs(), uses(); X X/* X * health.c X */ Xextern void rhealth(), bprep(); X X/* X * inst.c X */ Xextern void addinst(), delinst(), putinst(); Xextern bool opeq(); X X/* X * io.c X */ Xextern bool readline(); X X/* X * peep1.c X */ Xextern void peep(); X X/* X * reg.c X */ Xextern void addvar(), setreg(), clrvar(); X X/* X * util.c X */ Xextern char *alloc(); Xextern char *strsave(); X X/* X * sym.c X */ Xextern void freeop(), freesym(); Xextern BLOCK *getsym(), *mksym(); Xextern char *mktmp(); END_OF_FILE if test 3752 -ne `wc -c <'top/TOP.H'`; then echo shar: \"'top/TOP.H'\" unpacked with wrong size! fi # end of 'top/TOP.H' fi if test -f 'top/UTIL.C' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'top/UTIL.C'\" else echo shar: Extracting \"'top/UTIL.C'\" \(1057 characters\) sed "s/^X//" >'top/UTIL.C' <<'END_OF_FILE' X/* Copyright (c) 1988 by Sozobon, Limited. Author: Tony Andrews X * X * Permission is granted to anyone to use this software for any purpose X * on any computer system, and to redistribute it freely, with the X * following restrictions: X * 1) No charge may be made other than reasonable charges for reproduction. X * 2) Modified versions must be clearly marked as such. X * 3) The authors are not responsible for any harmful consequences X * of using this software, even if they result from defects in it. X */ X X#include <stdio.h> X X/* X * strsave(s) - copy s to dynamically allocated space X */ Xchar * Xstrsave(s) Xregister char *s; X{ X char *malloc(), *strcpy(); X X return strcpy(malloc((unsigned) (strlen(s) + 1)), s); X} X X/* X * alloc() - malloc with error checking X */ Xchar * Xalloc(n) Xint n; X{ X extern char *malloc(); X char *p; X X if ((p = malloc(n)) == NULL) { X fprintf(stderr, "top: out of memory\n"); X exit(1); X } X return p; X} X X#ifdef MINIX X Xremove(f) Xchar *f; X{ X unlink(f); X} X Xrename(f1, f2) Xchar *f1, *f2; X{ X unlink(f2); X link(f1, f2); X unlink(f1); X} X X#endif END_OF_FILE if test 1057 -ne `wc -c <'top/UTIL.C'`; then echo shar: \"'top/UTIL.C'\" unpacked with wrong size! fi # end of 'top/UTIL.C' fi echo shar: End of archive 1 \(of 9\). cp /dev/null ark1isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 9 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0