xref: /csrg-svn/usr.bin/pascal/src/fend.c (revision 10716)
13192Smckusick /* Copyright (c) 1979 Regents of the University of California */
23192Smckusick 
3*10716Speter static char sccsid[] = "@(#)fend.c 1.20 02/03/83";
43192Smckusick 
53192Smckusick #include "whoami.h"
63192Smckusick #include "0.h"
73192Smckusick #include "tree.h"
83192Smckusick #include "opcode.h"
93192Smckusick #include "objfmt.h"
103192Smckusick #include "align.h"
113192Smckusick 
123192Smckusick /*
133192Smckusick  * this array keeps the pxp counters associated with
143192Smckusick  * functions and procedures, so that they can be output
153192Smckusick  * when their bodies are encountered
163192Smckusick  */
173192Smckusick int	bodycnts[ DSPLYSZ ];
183192Smckusick 
193192Smckusick #ifdef PC
203192Smckusick #   include "pc.h"
213192Smckusick #   include "pcops.h"
223192Smckusick #endif PC
233192Smckusick 
243192Smckusick #ifdef OBJ
253192Smckusick int	cntpatch;
263192Smckusick int	nfppatch;
273192Smckusick #endif OBJ
283192Smckusick 
293192Smckusick struct	nl *Fp;
303192Smckusick int	pnumcnt;
313192Smckusick /*
323192Smckusick  * Funcend is called to
333192Smckusick  * finish a block by generating
343192Smckusick  * the code for the statements.
353192Smckusick  * It then looks for unresolved declarations
363192Smckusick  * of labels, procedures and functions,
373192Smckusick  * and cleans up the name list.
383192Smckusick  * For the program, it checks the
393192Smckusick  * semantics of the program
403192Smckusick  * statement (yuchh).
413192Smckusick  */
423192Smckusick funcend(fp, bundle, endline)
433192Smckusick 	struct nl *fp;
443192Smckusick 	int *bundle;
453192Smckusick 	int endline;
463192Smckusick {
473192Smckusick 	register struct nl *p;
483192Smckusick 	register int i, b;
493192Smckusick 	int var, inp, out, *blk;
503192Smckusick 	bool chkref;
513192Smckusick 	struct nl *iop;
523192Smckusick 	char *cp;
533192Smckusick 	extern int cntstat;
543192Smckusick #	ifdef PC
5510671Speter 	    struct entry_exit_cookie	eecookie;
563192Smckusick #	endif PC
573192Smckusick 
583192Smckusick 	cntstat = 0;
593192Smckusick /*
603192Smckusick  *	yyoutline();
613192Smckusick  */
623192Smckusick 	if (program != NIL)
633192Smckusick 		line = program->value[3];
643192Smckusick 	blk = bundle[2];
653192Smckusick 	if (fp == NIL) {
663192Smckusick 		cbn--;
673192Smckusick #		ifdef PTREE
683192Smckusick 		    nesting--;
693192Smckusick #		endif PTREE
703192Smckusick 		return;
713192Smckusick 	}
723192Smckusick #ifdef OBJ
733192Smckusick 	/*
743192Smckusick 	 * Patch the branch to the
753192Smckusick 	 * entry point of the function
763192Smckusick 	 */
777917Smckusick 	patch4(fp->value[NL_ENTLOC]);
783192Smckusick 	/*
793192Smckusick 	 * Put out the block entrance code and the block name.
803192Smckusick 	 * HDRSZE is the number of bytes of info in the static
813192Smckusick 	 * BEG data area exclusive of the proc name. It is
823192Smckusick 	 * currently defined as:
833192Smckusick 	/*	struct hdr {
843192Smckusick 	/*		long framesze;	/* number of bytes of local vars */
853192Smckusick 	/*		long nargs;	/* number of bytes of arguments */
863192Smckusick 	/*		bool tests;	/* TRUE => perform runtime tests */
873192Smckusick 	/*		short offset;	/* offset of procedure in source file */
883192Smckusick 	/*		char name[1];	/* name of active procedure */
893192Smckusick 	/*	};
903192Smckusick 	 */
913192Smckusick #	define HDRSZE (2 * sizeof(long) + sizeof(short) + sizeof(bool))
923192Smckusick 	var = put(2, ((lenstr(fp->symbol,0) + HDRSZE) << 8)
933192Smckusick 		| (cbn == 1 && opt('p') == 0 ? O_NODUMP: O_BEG), (long)0);
943192Smckusick 	    /*
953192Smckusick 	     *  output the number of bytes of arguments
963192Smckusick 	     *  this is only checked on formal calls.
973192Smckusick 	     */
983192Smckusick 	put(2, O_CASE4, cbn == 1 ? (long)0 : (long)(fp->value[NL_OFFS]-DPOFF2));
993192Smckusick 	    /*
1003192Smckusick 	     *	Output the runtime test mode for the routine
1013192Smckusick 	     */
1023192Smckusick 	put(2, sizeof(bool) == 2 ? O_CASE2 : O_CASE4, opt('t') ? TRUE : FALSE);
1033192Smckusick 	    /*
1043192Smckusick 	     *	Output line number and routine name
1053192Smckusick 	     */
1063192Smckusick 	put(2, O_CASE2, bundle[1]);
1073192Smckusick 	putstr(fp->symbol, 0);
1083192Smckusick #endif OBJ
1093192Smckusick #ifdef PC
1103192Smckusick 	/*
1113192Smckusick 	 * put out the procedure entry code
1123192Smckusick 	 */
11310671Speter 	eecookie.nlp = fp;
1143192Smckusick 	if ( fp -> class == PROG ) {
1159129Smckusick 		/*
1169129Smckusick 		 *	If there is a label declaration in the main routine
1179129Smckusick 		 *	then there may be a non-local goto to it that does
1189129Smckusick 		 *	not appear in this module. We have to assume that
1199129Smckusick 		 *	such a reference may occur and generate code to
1209129Smckusick 		 *	prepare for it.
1219129Smckusick 		 */
1229129Smckusick 	    if ( parts[ cbn ] & LPRT ) {
1239129Smckusick 		parts[ cbn ] |= ( NONLOCALVAR | NONLOCALGOTO );
1249129Smckusick 	    }
12510671Speter 	    codeformain();
1267917Smckusick 	    ftnno = fp -> value[NL_ENTLOC];
12710671Speter 	    prog_prologue(&eecookie);
1283192Smckusick 	    stabfunc( "program" , fp -> class , bundle[1] , 0 );
1293192Smckusick 	} else {
1307917Smckusick 	    ftnno = fp -> value[NL_ENTLOC];
13110671Speter 	    fp_prologue(&eecookie);
1323192Smckusick 	    stabfunc( fp -> symbol , fp -> class , bundle[1] , cbn - 1 );
1333192Smckusick 	    for ( p = fp -> chain ; p != NIL ; p = p -> chain ) {
1343192Smckusick 		stabparam( p -> symbol , p2type( p -> type )
1353192Smckusick 			    , p -> value[ NL_OFFS ] , lwidth( p -> type ) );
1363192Smckusick 	    }
1373192Smckusick 	    if ( fp -> class == FUNC ) {
1383192Smckusick 		    /*
1393192Smckusick 		     *	stab the function variable
1403192Smckusick 		     */
1413192Smckusick 		p = fp -> ptr[ NL_FVAR ];
1423192Smckusick 		stablvar( p -> symbol , p2type( p -> type ) , cbn
1433192Smckusick 			, p -> value[ NL_OFFS ] , lwidth( p -> type ) );
1443192Smckusick 	    }
1453192Smckusick 		/*
1463192Smckusick 		 *	stab local variables
1473192Smckusick 		 *	rummage down hash chain links.
1483192Smckusick 		 */
1493192Smckusick 	    for ( i = 0 ; i <= 077 ; i++ ) {
1503192Smckusick 		for ( p = disptab[ i ] ; p != NIL ; p = p->nl_next) {
1513192Smckusick 		    if ( ( p -> nl_block & 037 ) != cbn ) {
1523192Smckusick 			break;
1533192Smckusick 		    }
1543192Smckusick 		    /*
1553192Smckusick 		     *	stab local variables
1563192Smckusick 		     *	that's named variables, but not params
1573192Smckusick 		     */
1583192Smckusick 		    if (   ( p -> symbol != NIL )
1593192Smckusick 			&& ( p -> class == VAR )
1603192Smckusick 			&& ( p -> value[ NL_OFFS ] < 0 ) ) {
1613192Smckusick 			stablvar( p -> symbol , p2type( p -> type ) , cbn
1623192Smckusick 			    , p -> value[ NL_OFFS ] , lwidth( p -> type ) );
1633192Smckusick 		    }
1643192Smckusick 		}
1653192Smckusick 	    }
1663192Smckusick 	}
1673192Smckusick 	stablbrac( cbn );
1683192Smckusick 	    /*
1693192Smckusick 	     *	ask second pass to allocate known locals
1703192Smckusick 	     */
1713192Smckusick 	putlbracket( ftnno , -sizes[ cbn ].om_max );
17210671Speter 	fp_entrycode(&eecookie);
1733192Smckusick #endif PC
1743192Smckusick 	if ( monflg ) {
1753192Smckusick 		if ( fp -> value[ NL_CNTR ] != 0 ) {
1763192Smckusick 			inccnt( fp -> value [ NL_CNTR ] );
1773192Smckusick 		}
1783192Smckusick 		inccnt( bodycnts[ fp -> nl_block & 037 ] );
1793192Smckusick 	}
1803192Smckusick 	if (fp->class == PROG) {
1813192Smckusick 		/*
1823192Smckusick 		 * The glorious buffers option.
1833192Smckusick 		 *          0 = don't buffer output
1843192Smckusick 		 *          1 = line buffer output
1853192Smckusick 		 *          2 = 512 byte buffer output
1863192Smckusick 		 */
1873192Smckusick #		ifdef OBJ
1883192Smckusick 		    if (opt('b') != 1)
1893192Smckusick 			    put(1, O_BUFF | opt('b') << 8);
1903192Smckusick #		endif OBJ
1913192Smckusick #		ifdef PC
1923192Smckusick 		    if ( opt( 'b' ) != 1 ) {
1933192Smckusick 			putleaf( P2ICON , 0 , 0
1943192Smckusick 				, ADDTYPE( P2FTN | P2INT , P2PTR ) , "_BUFF" );
1953192Smckusick 			putleaf( P2ICON , opt( 'b' ) , 0 , P2INT , 0 );
1963192Smckusick 			putop( P2CALL , P2INT );
1973192Smckusick 			putdot( filename , line );
1983192Smckusick 		    }
1993192Smckusick #		endif PC
2007953Speter 		inp = 0;
2013192Smckusick 		out = 0;
2023192Smckusick 		for (p = fp->chain; p != NIL; p = p->chain) {
2037953Speter 			if (strcmp(p->symbol, input->symbol) == 0) {
2043192Smckusick 				inp++;
2053192Smckusick 				continue;
2063192Smckusick 			}
2077953Speter 			if (strcmp(p->symbol, output->symbol) == 0) {
2083192Smckusick 				out++;
2093192Smckusick 				continue;
2103192Smckusick 			}
2113192Smckusick 			iop = lookup1(p->symbol);
2123192Smckusick 			if (iop == NIL || bn != cbn) {
2133192Smckusick 				error("File %s listed in program statement but not declared", p->symbol);
2143192Smckusick 				continue;
2153192Smckusick 			}
2163192Smckusick 			if (iop->class != VAR) {
2173192Smckusick 				error("File %s listed in program statement but declared as a %s", p->symbol, classes[iop->class]);
2183192Smckusick 				continue;
2193192Smckusick 			}
2203192Smckusick 			if (iop->type == NIL)
2213192Smckusick 				continue;
2223192Smckusick 			if (iop->type->class != FILET) {
2233192Smckusick 				error("File %s listed in program statement but defined as %s",
2243192Smckusick 					p->symbol, nameof(iop->type));
2253192Smckusick 				continue;
2263192Smckusick 			}
2273192Smckusick #			ifdef OBJ
2283192Smckusick 			    put(2, O_CON24, text(iop->type) ? 0 : width(iop->type->type));
2293192Smckusick 			    i = lenstr(p->symbol,0);
2303192Smckusick 			    put(2, O_CON24, i);
2313192Smckusick 			    put(2, O_LVCON, i);
2323192Smckusick 			    putstr(p->symbol, 0);
2333192Smckusick 			    put(2, O_LV | bn<<8+INDX, (int)iop->value[NL_OFFS]);
2343192Smckusick 			    put(1, O_DEFNAME);
2353192Smckusick #			endif OBJ
2363192Smckusick #			ifdef PC
2373192Smckusick 			    putleaf( P2ICON , 0 , 0
2383192Smckusick 				    , ADDTYPE( P2FTN | P2INT , P2PTR )
2393192Smckusick 				    , "_DEFNAME" );
2403837Speter 			    putLV( p -> symbol , bn , iop -> value[NL_OFFS] ,
2413837Speter 				    iop -> extra_flags , p2type( iop ) );
2423192Smckusick 			    putCONG( p -> symbol , strlen( p -> symbol )
2433192Smckusick 				    , LREQ );
2443192Smckusick 			    putop( P2LISTOP , P2INT );
2453192Smckusick 			    putleaf( P2ICON , strlen( p -> symbol )
2463192Smckusick 				    , 0 , P2INT , 0 );
2473192Smckusick 			    putop( P2LISTOP , P2INT );
2483192Smckusick 			    putleaf( P2ICON
2493192Smckusick 				, text(iop->type) ? 0 : width(iop->type->type)
2503192Smckusick 				, 0 , P2INT , 0 );
2513192Smckusick 			    putop( P2LISTOP , P2INT );
2523192Smckusick 			    putop( P2CALL , P2INT );
2533192Smckusick 			    putdot( filename , line );
2543192Smckusick #			endif PC
2553192Smckusick 		}
2563192Smckusick 	}
2573192Smckusick 	/*
2583192Smckusick 	 * Process the prog/proc/func body
2593192Smckusick 	 */
2603192Smckusick 	noreach = 0;
2613192Smckusick 	line = bundle[1];
2623192Smckusick 	statlist(blk);
2633192Smckusick #	ifdef PTREE
2643192Smckusick 	    {
2653192Smckusick 		pPointer Body = tCopy( blk );
2663192Smckusick 
2673192Smckusick 		pDEF( PorFHeader[ nesting -- ] ).PorFBody = Body;
2683192Smckusick 	    }
2693192Smckusick #	endif PTREE
2703192Smckusick #	ifdef OBJ
2713192Smckusick 	    if (cbn== 1 && monflg != 0) {
2723192Smckusick 		    patchfil(cntpatch - 2, (long)cnts, 2);
2733192Smckusick 		    patchfil(nfppatch - 2, (long)pfcnt, 2);
2743192Smckusick 	    }
2753192Smckusick #	endif OBJ
2763192Smckusick #	ifdef PC
2773192Smckusick 	    if ( fp -> class == PROG && monflg ) {
2783192Smckusick 		putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR )
2793192Smckusick 			, "_PMFLUSH" );
2803192Smckusick 		putleaf( P2ICON , cnts , 0 , P2INT , 0 );
2813192Smckusick 		putleaf( P2ICON , pfcnt , 0 , P2INT , 0 );
2823192Smckusick 		putop( P2LISTOP , P2INT );
2833837Speter 		putLV( PCPCOUNT , 0 , 0 , NGLOBAL , P2INT );
2843192Smckusick 		putop( P2LISTOP , P2INT );
2853192Smckusick 		putop( P2CALL , P2INT );
2863192Smckusick 		putdot( filename , line );
2873192Smckusick 	    }
2883192Smckusick #	endif PC
2897953Speter 	/*
2907953Speter 	 * Clean up the symbol table displays and check for unresolves
2917953Speter 	 */
2927953Speter 	line = endline;
2933192Smckusick 	if (fp->class == PROG && inp == 0 && (input->nl_flags & (NUSED|NMOD)) != 0) {
2943192Smckusick 		recovered();
2953192Smckusick 		error("Input is used but not defined in the program statement");
2963192Smckusick 	}
2977953Speter 	if (fp->class == PROG && out == 0 && (output->nl_flags & (NUSED|NMOD)) != 0) {
2987953Speter 		recovered();
2997953Speter 		error("Output is used but not defined in the program statement");
3007953Speter 	}
3013192Smckusick 	b = cbn;
3023192Smckusick 	Fp = fp;
3033192Smckusick 	chkref = syneflg == errcnt[cbn] && opt('w') == 0;
3043192Smckusick 	for (i = 0; i <= 077; i++) {
3053192Smckusick 		for (p = disptab[i]; p != NIL && (p->nl_block & 037) == b; p = p->nl_next) {
3063192Smckusick 			/*
3073192Smckusick 			 * Check for variables defined
3083192Smckusick 			 * but not referenced
3093192Smckusick 			 */
3103192Smckusick 			if (chkref && p->symbol != NIL)
3113192Smckusick 			switch (p->class) {
3123192Smckusick 				case FIELD:
3133192Smckusick 					/*
3143192Smckusick 					 * If the corresponding record is
3153192Smckusick 					 * unused, we shouldn't complain about
3163192Smckusick 					 * the fields.
3173192Smckusick 					 */
3183192Smckusick 				default:
3193192Smckusick 					if ((p->nl_flags & (NUSED|NMOD)) == 0) {
3203192Smckusick 						warning();
3213192Smckusick 						nerror("%s %s is neither used nor set", classes[p->class], p->symbol);
3223192Smckusick 						break;
3233192Smckusick 					}
3243192Smckusick 					/*
3253192Smckusick 					 * If a var parameter is either
3263192Smckusick 					 * modified or used that is enough.
3273192Smckusick 					 */
3283192Smckusick 					if (p->class == REF)
3293192Smckusick 						continue;
3303192Smckusick #					ifdef OBJ
3313192Smckusick 					    if ((p->nl_flags & NUSED) == 0) {
3323192Smckusick 						warning();
3333192Smckusick 						nerror("%s %s is never used", classes[p->class], p->symbol);
3343192Smckusick 						break;
3353192Smckusick 					    }
3363192Smckusick #					endif OBJ
3373192Smckusick #					ifdef PC
3383837Speter 					    if (((p->nl_flags & NUSED) == 0) && ((p->extra_flags & NEXTERN) == 0)) {
3393192Smckusick 						warning();
3403192Smckusick 						nerror("%s %s is never used", classes[p->class], p->symbol);
3413192Smckusick 						break;
3423192Smckusick 					    }
3433192Smckusick #					endif PC
3443192Smckusick 					if ((p->nl_flags & NMOD) == 0) {
3453192Smckusick 						warning();
3463192Smckusick 						nerror("%s %s is used but never set", classes[p->class], p->symbol);
3473192Smckusick 						break;
3483192Smckusick 					}
3493192Smckusick 				case LABEL:
3503192Smckusick 				case FVAR:
3513192Smckusick 				case BADUSE:
3523192Smckusick 					break;
3533192Smckusick 			}
3543192Smckusick 			switch (p->class) {
3553192Smckusick 				case BADUSE:
3563192Smckusick 					cp = "s";
3573192Smckusick 					if (p->chain->ud_next == NIL)
3583192Smckusick 						cp++;
3593192Smckusick 					eholdnl();
3603192Smckusick 					if (p->value[NL_KINDS] & ISUNDEF)
3613192Smckusick 						nerror("%s undefined on line%s", p->symbol, cp);
3623192Smckusick 					else
3633192Smckusick 						nerror("%s improperly used on line%s", p->symbol, cp);
3643192Smckusick 					pnumcnt = 10;
3653192Smckusick 					pnums(p->chain);
3663192Smckusick 					pchr('\n');
3673192Smckusick 					break;
3683192Smckusick 
3693192Smckusick 				case FUNC:
3703192Smckusick 				case PROC:
3713192Smckusick #					ifdef OBJ
3723192Smckusick 					    if ((p->nl_flags & NFORWD))
3733192Smckusick 						nerror("Unresolved forward declaration of %s %s", classes[p->class], p->symbol);
3743192Smckusick #					endif OBJ
3753192Smckusick #					ifdef PC
3763837Speter 					    if ((p->nl_flags & NFORWD) && ((p->extra_flags & NEXTERN) == 0))
3773192Smckusick 						nerror("Unresolved forward declaration of %s %s", classes[p->class], p->symbol);
3783192Smckusick #					endif PC
3793192Smckusick 					break;
3803192Smckusick 
3813192Smckusick 				case LABEL:
3823192Smckusick 					if (p->nl_flags & NFORWD)
3833192Smckusick 						nerror("label %s was declared but not defined", p->symbol);
3843192Smckusick 					break;
3853192Smckusick 				case FVAR:
3863192Smckusick 					if ((p->nl_flags & NMOD) == 0)
3873192Smckusick 						nerror("No assignment to the function variable");
3883192Smckusick 					break;
3893192Smckusick 			}
3903192Smckusick 		}
3913192Smckusick 		/*
3923192Smckusick 		 * Pop this symbol
3933192Smckusick 		 * table slot
3943192Smckusick 		 */
3953192Smckusick 		disptab[i] = p;
3963192Smckusick 	}
3973192Smckusick 
3983192Smckusick #	ifdef OBJ
3993192Smckusick 	    put(1, O_END);
4003192Smckusick #	endif OBJ
4013192Smckusick #	ifdef PC
40210671Speter 	    fp_exitcode(&eecookie);
40310671Speter 	    stabrbrac(cbn);
40410671Speter 	    putrbracket(ftnno);
40510671Speter 	    fp_epilogue(&eecookie);
40610671Speter 	    if (fp -> class != PROG) {
40710671Speter 		fp_formalentry(&eecookie);
4083192Smckusick 	    }
4093192Smckusick 		/*
4103192Smckusick 		 *	declare pcp counters, if any
4113192Smckusick 		 */
4123192Smckusick 	    if ( monflg && fp -> class == PROG ) {
4133192Smckusick 		putprintf( "	.data" , 0 );
41410671Speter 		aligndot(P2INT);
4153192Smckusick 		putprintf( "	.comm	" , 1 );
4163192Smckusick 		putprintf( PCPCOUNT , 1 );
4173192Smckusick 		putprintf( ",%d" , 0 , ( cnts + 1 ) * sizeof (long) );
4183192Smckusick 		putprintf( "	.text" , 0 );
4193192Smckusick 	    }
4203192Smckusick #	endif PC
4213192Smckusick #ifdef DEBUG
4223192Smckusick 	dumpnl(fp->ptr[2], fp->symbol);
4233192Smckusick #endif
4245654Slinton 
4255654Slinton #ifdef OBJ
4263192Smckusick 	/*
4275654Slinton 	 * save the namelist for the debugger pdx
4285654Slinton 	 */
4295654Slinton 
4305654Slinton 	savenl(fp->ptr[2], fp->symbol);
4315654Slinton #endif
4325654Slinton 
4335654Slinton 	/*
4343192Smckusick 	 * Restore the
4353192Smckusick 	 * (virtual) name list
4363192Smckusick 	 * position
4373192Smckusick 	 */
4383192Smckusick 	nlfree(fp->ptr[2]);
4393192Smckusick 	/*
4403192Smckusick 	 * Proc/func has been
4413192Smckusick 	 * resolved
4423192Smckusick 	 */
4433192Smckusick 	fp->nl_flags &= ~NFORWD;
4443192Smckusick 	/*
4453192Smckusick 	 * Patch the beg
4463192Smckusick 	 * of the proc/func to
4473192Smckusick 	 * the proper variable size
4483192Smckusick 	 */
4493192Smckusick 	if (Fp == NIL)
4503192Smckusick 		elineon();
4513192Smckusick #	ifdef OBJ
45210671Speter 	    patchfil(var, leven(-sizes[cbn].om_max), 2);
4533192Smckusick #	endif OBJ
4543192Smckusick 	cbn--;
4553192Smckusick 	if (inpflist(fp->symbol)) {
4563192Smckusick 		opop('l');
4573192Smckusick 	}
4583192Smckusick }
4593363Speter 
4603363Speter #ifdef PC
4613363Speter     /*
4623363Speter      *	construct the long name of a function based on it's static nesting.
4633363Speter      *	into a caller-supplied buffer (that should be about BUFSIZ big).
4643363Speter      */
4653363Speter sextname( buffer , name , level )
4663363Speter     char	buffer[];
4673363Speter     char	*name;
4683363Speter     int		level;
4693363Speter {
4703363Speter     char	*starthere;
4713363Speter     int	i;
4723363Speter 
4733363Speter     starthere = &buffer[0];
4743363Speter     for ( i = 1 ; i < level ; i++ ) {
4753363Speter 	sprintf( starthere , EXTFORMAT , enclosing[ i ] );
4763363Speter 	starthere += strlen( enclosing[ i ] ) + 1;
4773363Speter     }
4783367Speter     sprintf( starthere , EXTFORMAT , name );
4793367Speter     starthere += strlen( name ) + 1;
4803363Speter     if ( starthere >= &buffer[ BUFSIZ ] ) {
4813363Speter 	panic( "sextname" );
4823363Speter     }
4833363Speter }
48410671Speter 
48510671Speter     /*
48610671Speter      *	code for main()
48710671Speter      */
48810671Speter #ifdef vax
48910671Speter 
49010671Speter codeformain()
49110671Speter {
49210671Speter     putprintf("	.text" , 0 );
49310671Speter     putprintf("	.align	1" , 0 );
49410671Speter     putprintf("	.globl	_main" , 0 );
49510671Speter     putprintf("_main:" , 0 );
49610671Speter     putprintf("	.word	0" , 0 );
49710671Speter     if ( opt ( 't' ) ) {
49810671Speter 	putprintf("	pushl	$1" , 0 );
49910671Speter     } else {
50010671Speter 	putprintf("	pushl	$0" , 0 );
50110671Speter     }
50210671Speter     putprintf("	calls	$1,_PCSTART" , 0 );
50310671Speter     putprintf("	movl	4(ap),__argc" , 0 );
50410671Speter     putprintf("	movl	8(ap),__argv" , 0 );
50510671Speter     putprintf("	calls	$0,_program" , 0 );
50610671Speter     putprintf("	pushl	$0" , 0 );
50710671Speter     putprintf("	calls	$1,_PCEXIT" , 0 );
50810671Speter }
50910671Speter 
51010671Speter     /*
51110671Speter      *	prologue for the program.
51210671Speter      *	different because it
51310671Speter      *		doesn't have formal entry point
51410671Speter      */
51510671Speter prog_prologue(eecookiep)
51610671Speter     struct entry_exit_cookie	*eecookiep;
51710671Speter {
51810671Speter     putprintf("	.text" , 0 );
51910671Speter     putprintf("	.align	1" , 0 );
52010671Speter     putprintf("	.globl	_program" , 0 );
52110671Speter     putprintf("_program:" , 0 );
522*10716Speter 	/*
523*10716Speter 	 *	register save mask
524*10716Speter 	 */
525*10716Speter     eecookiep -> savlabel = getlab();
526*10716Speter     putprintf("	.word	%s%d", 0, SAVE_MASK_LABEL , eecookiep -> savlabel );
52710671Speter }
52810671Speter 
52910671Speter fp_prologue(eecookiep)
53010671Speter     struct entry_exit_cookie	*eecookiep;
53110671Speter {
53210671Speter     int		ftnno = eecookiep -> nlp -> value[NL_ENTLOC];
53310671Speter 
53410671Speter     sextname( eecookiep -> extname, eecookiep -> nlp -> symbol , cbn - 1 );
53510671Speter     putprintf( "	.text" , 0 );
53610671Speter     putprintf( "	.align	1" , 0 );
53710671Speter     putprintf( "	.globl	%s%s", 0, FORMALPREFIX, eecookiep -> extname );
53810671Speter     putprintf( "	.globl	%s" , 0 , eecookiep -> extname );
53910671Speter     putprintf( "%s:" , 0 , eecookiep -> extname );
54010671Speter 	/*
54110671Speter 	 *	register save mask
54210671Speter 	 */
54310671Speter     eecookiep -> savlabel = getlab();
54410671Speter     putprintf("	.word	%s%d", 0, SAVE_MASK_LABEL , eecookiep -> savlabel );
54510671Speter }
54610671Speter 
54710671Speter     /*
54810671Speter      *	code before any user code.
54910671Speter      *	or code that is machine dependent.
55010671Speter      */
55110671Speter fp_entrycode(eecookiep)
55210671Speter     struct entry_exit_cookie	*eecookiep;
55310671Speter {
55410714Speter     int	ftnno = eecookiep -> nlp -> value[NL_ENTLOC];
55510671Speter     int	proflabel = getlab();
55610671Speter     int	setjmp0 = getlab();
55710671Speter 
55810671Speter 	/*
55910671Speter 	 *	top of code;  destination of jump from formal entry code.
56010671Speter 	 */
56110671Speter     eecookiep -> toplabel = getlab();
56210671Speter     putlab( eecookiep -> toplabel );
56310671Speter     putprintf("	subl2	$%s%d,sp" , 0 , FRAME_SIZE_LABEL, ftnno );
56410671Speter     if ( profflag ) {
56510671Speter 	    /*
56610671Speter 	     *	call mcount for profiling
56710671Speter 	     */
56810671Speter 	putprintf( "	moval	" , 1 );
56910671Speter 	putprintf( PREFIXFORMAT , 1 , LABELPREFIX , proflabel );
57010671Speter 	putprintf( ",r0" , 0 );
57110671Speter 	putprintf( "	jsb	mcount" , 0 );
57210671Speter 	putprintf( "	.data" , 0 );
57310671Speter 	putprintf( "	.align	2" , 0 );
57410671Speter 	putlab( proflabel );
57510671Speter 	putprintf( "	.long	0" , 0 );
57610671Speter 	putprintf( "	.text" , 0 );
57710671Speter     }
57810671Speter 	/*
57910671Speter 	 *	if there are nested procedures that access our variables
58010671Speter 	 *	we must save the display.
58110671Speter 	 */
58210671Speter     if ( parts[ cbn ] & NONLOCALVAR ) {
58310671Speter 	    /*
58410671Speter 	     *	save old display
58510671Speter 	     */
58610671Speter 	putprintf( "	movq	%s+%d,%d(%s)" , 0
58710671Speter 		, DISPLAYNAME , cbn * sizeof(struct dispsave)
58810671Speter 		, DSAVEOFFSET , P2FPNAME );
58910671Speter 	    /*
59010671Speter 	     *	set up new display by saving AP and FP in appropriate
59110671Speter 	     *	slot in display structure.
59210671Speter 	     */
59310671Speter 	putprintf( "	movq	%s,%s+%d" , 0
59410671Speter 		, P2APNAME , DISPLAYNAME , cbn * sizeof(struct dispsave) );
59510671Speter     }
59610671Speter 	/*
59710671Speter 	 *	set underflow checking if runtime tests
59810671Speter 	 */
59910671Speter     if ( opt( 't' ) ) {
60010671Speter 	putprintf( "	bispsw	$0xe0" , 0 );
60110671Speter     }
60210671Speter 	/*
60310671Speter 	 *	zero local variables if checking is on
60410671Speter 	 *	by calling blkclr( bytes of locals , starting local address );
60510671Speter 	 */
60610671Speter     if ( opt( 't' ) && ( -sizes[ cbn ].om_max ) > DPOFF1 ) {
60710671Speter 	putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR )
60810671Speter 		, "_blkclr" );
60910671Speter 	putLV( 0 , cbn , sizes[ cbn ].om_max , NLOCAL , P2CHAR );
61010671Speter 	putleaf( P2ICON ,  ( -sizes[ cbn ].om_max ) - DPOFF1
61110671Speter 		, 0 , P2INT , 0 );
61210671Speter 	putop( P2LISTOP , P2INT );
61310671Speter 	putop( P2CALL , P2INT );
61410671Speter 	putdot( filename , line );
61510671Speter     }
61610671Speter 	/*
61710671Speter 	 *  set up goto vector if non-local goto to this frame
61810671Speter 	 */
61910671Speter     if ( parts[ cbn ] & NONLOCALGOTO ) {
62010671Speter 	putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR )
62110671Speter 		, "_setjmp" );
62210671Speter 	putLV( 0 , cbn , GOTOENVOFFSET , NLOCAL , P2PTR|P2STRTY );
62310671Speter 	putop( P2CALL , P2INT );
62410671Speter 	putleaf( P2ICON , 0 , 0 , P2INT , 0 );
62510671Speter 	putop( P2NE , P2INT );
62610671Speter 	putleaf( P2ICON , setjmp0 , 0 , P2INT , 0 );
62710671Speter 	putop( P2CBRANCH , P2INT );
62810671Speter 	putdot( filename , line );
62910671Speter 	    /*
63010671Speter 	     *	on non-local goto, setjmp returns with address to
63110671Speter 	     *	be branched to.
63210671Speter 	     */
63310671Speter 	putprintf( "	jmp	(r0)" , 0 );
63410671Speter 	putlab(setjmp0);
63510671Speter     }
63610671Speter }
63710671Speter 
63810671Speter fp_exitcode(eecookiep)
63910671Speter     struct entry_exit_cookie	*eecookiep;
64010671Speter {
64110671Speter 	/*
64210671Speter 	 *	if there were file variables declared at this level
64310671Speter 	 *	call PCLOSE( ap ) to clean them up.
64410671Speter 	 */
64510671Speter     if ( dfiles[ cbn ] ) {
64610671Speter 	putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR )
64710671Speter 		, "_PCLOSE" );
64810671Speter 	putleaf( P2REG , 0 , P2AP , ADDTYPE( P2CHAR , P2PTR ) , 0 );
64910671Speter 	putop( P2CALL , P2INT );
65010671Speter 	putdot( filename , line );
65110671Speter     }
65210671Speter 	/*
65310671Speter 	 *	if this is a function,
65410671Speter 	 *	the function variable is the return value.
65510671Speter 	 *	if it's a scalar valued function, return scalar,
65610671Speter 	 *	else, return a pointer to the structure value.
65710671Speter 	 */
65810671Speter     if ( eecookiep-> nlp -> class == FUNC ) {
65910671Speter 	struct nl	*fvar = eecookiep-> nlp -> ptr[ NL_FVAR ];
66010671Speter 	long		fvartype = p2type( fvar -> type );
66110671Speter 	long		label;
66210671Speter 	char		labelname[ BUFSIZ ];
66310671Speter 
66410671Speter 	switch ( classify( fvar -> type ) ) {
66510671Speter 	    case TBOOL:
66610671Speter 	    case TCHAR:
66710671Speter 	    case TINT:
66810671Speter 	    case TSCAL:
66910671Speter 	    case TDOUBLE:
67010671Speter 	    case TPTR:
67110671Speter 		putRV( fvar -> symbol , ( fvar -> nl_block ) & 037 ,
67210671Speter 			fvar -> value[ NL_OFFS ] ,
67310671Speter 			fvar -> extra_flags ,
67410671Speter 			fvartype );
67510671Speter 		break;
67610671Speter 	    default:
67710671Speter 		label = getlab();
67810671Speter 		sprintf( labelname , PREFIXFORMAT , LABELPREFIX , label );
67910671Speter 		putprintf( "	.data" , 0 );
68010671Speter 		aligndot(A_STRUCT);
68110671Speter 		putprintf( "	.lcomm	%s,%d" , 0 ,
68210671Speter 			    labelname , lwidth( fvar -> type ) );
68310671Speter 		putprintf( "	.text" , 0 );
68410671Speter 		putleaf( P2NAME , 0 , 0 , fvartype , labelname );
68510671Speter 		putLV( fvar -> symbol , ( fvar -> nl_block ) & 037 ,
68610671Speter 			fvar -> value[ NL_OFFS ] ,
68710671Speter 			fvar -> extra_flags ,
68810671Speter 			fvartype );
68910671Speter 		putstrop( P2STASG , fvartype , lwidth( fvar -> type ) ,
69010671Speter 			align( fvar -> type ) );
69110671Speter 		putdot( filename , line );
69210671Speter 		putleaf( P2ICON , 0 , 0 , fvartype , labelname );
69310671Speter 		break;
69410671Speter 	}
69510671Speter 	putop( P2FORCE , fvartype );
69610671Speter 	putdot( filename , line );
69710671Speter     }
69810671Speter 	/*
69910671Speter 	 *	if there are nested procedures we must save the display.
70010671Speter 	 */
70110671Speter     if ( parts[ cbn ] & NONLOCALVAR ) {
70210671Speter 	    /*
70310671Speter 	     *	restore old display entry from save area
70410671Speter 	     */
70510671Speter 	putprintf( "	movq	%d(%s),%s+%d" , 0
70610671Speter 	    , DSAVEOFFSET , P2FPNAME
70710671Speter 	    , DISPLAYNAME , cbn * sizeof(struct dispsave) );
70810671Speter     }
70910671Speter }
71010671Speter 
71110671Speter fp_epilogue(eecookiep)
71210671Speter     struct entry_exit_cookie	*eecookiep;
71310671Speter {
71410671Speter     putprintf("	ret" , 0 );
71510671Speter 	/*
71610671Speter 	 *	set the register save mask.
71710671Speter 	 */
71810671Speter     putprintf("	.set	%s%d,0x%x", 0,
71910671Speter 		SAVE_MASK_LABEL, eecookiep -> savlabel, savmask());
72010671Speter }
72110671Speter 
72210671Speter fp_formalentry(eecookiep)
72310671Speter     struct entry_exit_cookie	*eecookiep;
72410671Speter {
72510671Speter 
72610671Speter     putprintf("%s%s:" , 0 , FORMALPREFIX , eecookiep -> extname );
72710671Speter     putprintf("	.word	%s%d", 0, SAVE_MASK_LABEL, eecookiep -> savlabel );
72810671Speter     putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) , "_FCALL" );
72910671Speter     putRV( 0 , cbn ,
73010671Speter 	eecookiep -> nlp -> value[ NL_OFFS ] + sizeof( struct formalrtn * ) ,
73110671Speter 	NPARAM , P2PTR | P2STRTY );
73210671Speter     putRV(0, cbn, eecookiep -> nlp -> value[NL_OFFS], NPARAM, P2PTR|P2STRTY);
73310671Speter     putop( P2LISTOP , P2INT );
73410671Speter     putop( P2CALL , P2INT );
73510671Speter     putdot( filename , line );
73610671Speter     putjbr( eecookiep -> toplabel );
73710671Speter }
73810671Speter #endif vax
73910671Speter 
74010671Speter #ifdef mc68000
74110671Speter 
74210671Speter codeformain()
74310671Speter {
74410671Speter     putprintf("	.text", 0);
74510671Speter     putprintf("	.globl	_main", 0);
74610671Speter     putprintf("_main:", 0);
74710671Speter     putprintf("	link	%s,#0", 0, P2FPNAME);
74810671Speter     if (opt('t')) {
74910671Speter 	putprintf("	pea	1", 0);
75010671Speter     } else {
75110671Speter 	putprintf("	pea	0", 0);
75210671Speter     }
75310671Speter     putprintf("	jbsr	_PCSTART", 0);
75410671Speter     putprintf("	addql	#4,sp", 0);
75510671Speter     putprintf("	movl	%s@(8),__argc", 0, P2FPNAME);
75610671Speter     putprintf("	movl	%s@(12),__argv", 0, P2FPNAME);
75710671Speter     putprintf("	jbsr	_program", 0);
75810671Speter     putprintf("	pea	0", 0);
75910671Speter     putprintf("	jbsr	_PCEXIT", 0);
76010671Speter }
76110671Speter 
76210671Speter prog_prologue(eecookiep)
76310671Speter     struct entry_exit_cookie	*eecookiep;
76410671Speter {
76510671Speter     int	ftnno = eecookiep -> nlp -> value[NL_ENTLOC];
76610671Speter 
76710671Speter     putprintf("	.text", 0);
76810671Speter     putprintf("	.globl	_program", 0);
76910671Speter     putprintf("_program:", 0);
77010671Speter     putprintf("	link	%s,#0", 0, P2FPNAME);
77110671Speter     putprintf("	addl	#-%s%d,sp", 0, FRAME_SIZE_LABEL, ftnno);
77210671Speter 	/* touch new end of stack, to break more stack space */
77310671Speter     putprintf("	tstb	sp@(-%s%d)", 0, PAGE_BREAK_LABEL, ftnno);
77410671Speter     putprintf("	moveml	#%s%d,sp@", 0, SAVE_MASK_LABEL, ftnno);
77510671Speter }
77610671Speter 
77710671Speter fp_prologue(eecookiep)
77810671Speter     struct entry_exit_cookie	*eecookiep;
77910671Speter {
78010671Speter     int		ftnno = eecookiep -> nlp -> value[NL_ENTLOC];
78110671Speter 
78210671Speter     sextname(eecookiep -> extname, eecookiep -> nlp -> symbol, cbn - 1);
78310671Speter     putprintf("	.text", 0);
78410671Speter     putprintf("	.globl	%s%s", 0, FORMALPREFIX, eecookiep -> extname);
78510671Speter     putprintf("	.globl	%s", 0, eecookiep -> extname);
78610671Speter     putprintf("%s:", 0, eecookiep -> extname);
78710671Speter     putprintf("	link	%s,#0", 0, P2FPNAME);
78810671Speter     putprintf("	addl	#-%s%d,sp", 0, FRAME_SIZE_LABEL, ftnno);
78910671Speter 	/* touch new end of stack, to break more stack space */
79010671Speter     putprintf("	tstb	sp@(-%s%d)", 0, PAGE_BREAK_LABEL, ftnno);
79110671Speter     putprintf("	moveml	#%s%d,sp@", 0, SAVE_MASK_LABEL, ftnno);
79210671Speter }
79310671Speter 
79410671Speter fp_entrycode(eecookiep)
79510671Speter     struct entry_exit_cookie	*eecookiep;
79610671Speter {
79710671Speter     int	proflabel = getlab();
79810671Speter     int	setjmp0 = getlab();
79910671Speter 
80010671Speter 	/*
80110671Speter 	 *	fill in the label cookie
80210671Speter 	 */
80310671Speter     eecookiep -> toplabel = getlab();
80410671Speter     putlab(eecookiep -> toplabel);
80510671Speter 	/*
80610671Speter 	 *	call mcount if we are profiling.
80710671Speter 	 */
80810671Speter     if ( profflag ) {
80910671Speter 	putprintf("	movl	#%s%d,a0", 0, LABELPREFIX,  proflabel);
81010671Speter 	putprintf("	jsr	mcount", 0);
81110671Speter 	putprintf("	.data", 0);
81210671Speter 	putprintf("	.even", 0);
81310671Speter 	putlab(proflabel);
81410671Speter 	putprintf("	.long	0", 0);
81510671Speter 	putprintf("	.text", 0);
81610671Speter     }
81710671Speter 	/*
81810671Speter 	 *	if there are nested procedures that access our variables
81910671Speter 	 *	we must save the display
82010671Speter 	 */
82110671Speter     if (parts[cbn] & NONLOCALVAR) {
82210671Speter 	    /*
82310671Speter 	     *	save the old display
82410671Speter 	     */
82510671Speter 	putprintf("	movl	%s+%d,%s@(%d)", 0,
82610671Speter 		    DISPLAYNAME, cbn * sizeof(struct dispsave),
82710671Speter 		    P2FPNAME, DSAVEOFFSET);
82810671Speter 	    /*
82910671Speter 	     *	set up the new display by saving the framepointer
83010671Speter 	     *	in the display structure.
83110671Speter 	     */
83210671Speter 	putprintf("	movl	%s,%s+%d", 0,
83310671Speter 		    P2FPNAME, DISPLAYNAME, cbn * sizeof(struct dispsave));
83410671Speter     }
83510671Speter 	/*
83610671Speter 	 *	zero local variables if checking is on
83710671Speter 	 *	by calling blkclr( bytes of locals , starting local address );
83810671Speter 	 */
83910671Speter     if ( opt( 't' ) && ( -sizes[ cbn ].om_max ) > DPOFF1 ) {
84010671Speter 	putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR )
84110671Speter 		, "_blkclr" );
84210671Speter 	putLV( 0 , cbn , sizes[ cbn ].om_max , NLOCAL , P2CHAR );
84310671Speter 	putleaf( P2ICON ,  ( -sizes[ cbn ].om_max ) - DPOFF1
84410671Speter 		, 0 , P2INT , 0 );
84510671Speter 	putop( P2LISTOP , P2INT );
84610671Speter 	putop( P2CALL , P2INT );
84710671Speter 	putdot( filename , line );
84810671Speter     }
84910671Speter 	/*
85010671Speter 	 *  set up goto vector if non-local goto to this frame
85110671Speter 	 */
85210671Speter     if ( parts[ cbn ] & NONLOCALGOTO ) {
85310671Speter 	putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR )
85410671Speter 		, "_setjmp" );
85510671Speter 	putLV( 0 , cbn , GOTOENVOFFSET , NLOCAL , P2PTR|P2STRTY );
85610671Speter 	putop( P2CALL , P2INT );
85710671Speter 	putleaf( P2ICON , 0 , 0 , P2INT , 0 );
85810671Speter 	putop( P2NE , P2INT );
85910671Speter 	putleaf( P2ICON , setjmp0 , 0 , P2INT , 0 );
86010671Speter 	putop( P2CBRANCH , P2INT );
86110671Speter 	putdot( filename , line );
86210671Speter 	    /*
86310671Speter 	     *	on non-local goto, setjmp returns with address to
86410671Speter 	     *	be branched to.
86510671Speter 	     */
86610671Speter 	putprintf("	movl	d0,a0", 0);
86710671Speter 	putprintf("	jmp	a0@", 0);
86810671Speter 	putlab(setjmp0);
86910671Speter     }
87010671Speter }
87110671Speter 
87210671Speter fp_exitcode(eecookiep)
87310671Speter     struct entry_exit_cookie	*eecookiep;
87410671Speter {
87510671Speter 	/*
87610671Speter 	 *	if there were file variables declared at this level
87710671Speter 	 *	call PCLOSE( ap ) to clean them up.
87810671Speter 	 */
87910671Speter     if ( dfiles[ cbn ] ) {
88010671Speter 	putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR )
88110671Speter 		, "_PCLOSE" );
88210671Speter 	putleaf( P2REG , 0 , P2AP , ADDTYPE( P2CHAR , P2PTR ) , 0 );
88310671Speter 	putop( P2CALL , P2INT );
88410671Speter 	putdot( filename , line );
88510671Speter     }
88610671Speter 	/*
88710671Speter 	 *	if this is a function,
88810671Speter 	 *	the function variable is the return value.
88910671Speter 	 *	if it's a scalar valued function, return scalar,
89010671Speter 	 *	else, return a pointer to the structure value.
89110671Speter 	 */
89210671Speter     if ( eecookiep -> nlp -> class == FUNC ) {
89310671Speter 	struct nl	*fvar = eecookiep -> nlp -> ptr[ NL_FVAR ];
89410671Speter 	long		fvartype = p2type( fvar -> type );
89510671Speter 	long		label;
89610671Speter 	char		labelname[ BUFSIZ ];
89710671Speter 
89810671Speter 	switch ( classify( fvar -> type ) ) {
89910671Speter 	    case TBOOL:
90010671Speter 	    case TCHAR:
90110671Speter 	    case TINT:
90210671Speter 	    case TSCAL:
90310671Speter 	    case TDOUBLE:
90410671Speter 	    case TPTR:
90510671Speter 		putRV( fvar -> symbol , ( fvar -> nl_block ) & 037 ,
90610671Speter 			fvar -> value[ NL_OFFS ] ,
90710671Speter 			fvar -> extra_flags ,
90810671Speter 			fvartype );
90910671Speter 		break;
91010671Speter 	    default:
91110671Speter 		label = getlab();
91210671Speter 		sprintf( labelname , PREFIXFORMAT , LABELPREFIX , label );
91310671Speter 		putprintf("	.lcomm	%s,%d", 0,
91410671Speter 			labelname, lwidth(fvar -> type));
91510671Speter 		putleaf( P2NAME , 0 , 0 , fvartype , labelname );
91610671Speter 		putLV( fvar -> symbol , ( fvar -> nl_block ) & 037 ,
91710671Speter 			fvar -> value[ NL_OFFS ] ,
91810671Speter 			fvar -> extra_flags ,
91910671Speter 			fvartype );
92010671Speter 		putstrop( P2STASG , fvartype , lwidth( fvar -> type ) ,
92110671Speter 			align( fvar -> type ) );
92210671Speter 		putdot( filename , line );
92310671Speter 		putleaf( P2ICON , 0 , 0 , fvartype , labelname );
92410671Speter 		break;
92510671Speter 	}
92610671Speter 	putop( P2FORCE , fvartype );
92710671Speter 	putdot( filename , line );
92810671Speter     }
92910671Speter 	/*
93010671Speter 	 *	if we saved a display, we must restore it.
93110671Speter 	 */
93210671Speter     if ( parts[ cbn ] & NONLOCALVAR ) {
93310671Speter 	    /*
93410671Speter 	     *	restore old display entry from save area
93510671Speter 	     */
93610671Speter 	putprintf("	movl	%s@(%d),%s+%d", 0,
93710671Speter 		    P2FPNAME, DSAVEOFFSET,
93810671Speter 		    DISPLAYNAME, cbn * sizeof(struct dispsave));
93910671Speter     }
94010671Speter }
94110671Speter 
94210671Speter fp_epilogue(eecookiep)
94310671Speter     struct entry_exit_cookie	*eecookiep;
94410671Speter {
94510671Speter     /*
94610671Speter      *	all done by the second pass.
94710671Speter      */
94810671Speter }
94910671Speter 
95010671Speter fp_formalentry(eecookiep)
95110671Speter     struct entry_exit_cookie	*eecookiep;
95210671Speter {
95310671Speter     putprintf( "%s%s:" , 0 , FORMALPREFIX , eecookiep -> extname );
95410671Speter     putprintf("	link	%s,#0", 0, P2FPNAME);
95510671Speter     putprintf("	addl	#-%s%d,sp", 0, FRAME_SIZE_LABEL, ftnno);
95610671Speter 	/* touch new end of stack, to break more stack space */
95710671Speter     putprintf("	tstb	sp@(-%s%d)", 0, PAGE_BREAK_LABEL, ftnno);
95810671Speter     putprintf("	moveml	#%s%d,sp@", 0, SAVE_MASK_LABEL, ftnno);
95910671Speter     putleaf( P2ICON , 0 , 0 , ADDTYPE( P2FTN | P2INT , P2PTR ) , "_FCALL" );
96010671Speter     putRV( 0 , cbn ,
96110671Speter 	eecookiep -> nlp -> value[ NL_OFFS ] + sizeof( struct formalrtn * ) ,
96210671Speter 	NPARAM , P2PTR | P2STRTY );
96310671Speter     putRV(0, cbn, eecookiep -> nlp -> value[NL_OFFS], NPARAM, P2PTR|P2STRTY);
96410671Speter     putop( P2LISTOP , P2INT );
96510671Speter     putop( P2CALL , P2INT );
96610671Speter     putdot( filename , line );
96710671Speter     putjbr( eecookiep -> toplabel );
96810671Speter }
96910671Speter #endif mc68000
9703363Speter #endif PC
971