xref: /csrg-svn/usr.bin/pascal/src/fend.c (revision 22164)
1*22164Sdist /*
2*22164Sdist  * Copyright (c) 1980 Regents of the University of California.
3*22164Sdist  * All rights reserved.  The Berkeley software License Agreement
4*22164Sdist  * specifies the terms and conditions for redistribution.
5*22164Sdist  */
63192Smckusick 
718347Smckusick #ifndef lint
8*22164Sdist static char sccsid[] = "@(#)fend.c	5.1 (Berkeley) 06/05/85";
9*22164Sdist #endif not lint
103192Smckusick 
113192Smckusick #include "whoami.h"
123192Smckusick #include "0.h"
133192Smckusick #include "tree.h"
143192Smckusick #include "opcode.h"
153192Smckusick #include "objfmt.h"
163192Smckusick #include "align.h"
1711337Speter #include "tmps.h"
183192Smckusick 
193192Smckusick /*
203192Smckusick  * this array keeps the pxp counters associated with
213192Smckusick  * functions and procedures, so that they can be output
223192Smckusick  * when their bodies are encountered
233192Smckusick  */
243192Smckusick int	bodycnts[ DSPLYSZ ];
253192Smckusick 
263192Smckusick #ifdef PC
273192Smckusick #   include "pc.h"
2818457Sralph #   include <pcc.h>
293192Smckusick #endif PC
303192Smckusick 
313192Smckusick #ifdef OBJ
323192Smckusick int	cntpatch;
333192Smckusick int	nfppatch;
343192Smckusick #endif OBJ
353192Smckusick 
3618347Smckusick #include "tree_ty.h"
3718347Smckusick 
383192Smckusick struct	nl *Fp;
393192Smckusick int	pnumcnt;
403192Smckusick /*
413192Smckusick  * Funcend is called to
423192Smckusick  * finish a block by generating
433192Smckusick  * the code for the statements.
443192Smckusick  * It then looks for unresolved declarations
453192Smckusick  * of labels, procedures and functions,
463192Smckusick  * and cleans up the name list.
473192Smckusick  * For the program, it checks the
483192Smckusick  * semantics of the program
493192Smckusick  * statement (yuchh).
503192Smckusick  */
513192Smckusick funcend(fp, bundle, endline)
523192Smckusick 	struct nl *fp;
5318347Smckusick 	struct tnode *bundle;
543192Smckusick 	int endline;
553192Smckusick {
563192Smckusick 	register struct nl *p;
573192Smckusick 	register int i, b;
5818347Smckusick 	int inp, out;
5918347Smckusick 	struct tnode *blk;
603192Smckusick 	bool chkref;
613192Smckusick 	struct nl *iop;
623192Smckusick 	char *cp;
633192Smckusick 	extern int cntstat;
643192Smckusick #	ifdef PC
6510671Speter 	    struct entry_exit_cookie	eecookie;
663192Smckusick #	endif PC
6718347Smckusick #	ifndef PC
6818347Smckusick 	int var;
6918347Smckusick #	endif PC
703192Smckusick 
713192Smckusick 	cntstat = 0;
723192Smckusick /*
733192Smckusick  *	yyoutline();
743192Smckusick  */
753192Smckusick 	if (program != NIL)
763192Smckusick 		line = program->value[3];
7718347Smckusick 	blk = bundle->stmnt_blck.stmnt_list;
783192Smckusick 	if (fp == NIL) {
793192Smckusick 		cbn--;
803192Smckusick #		ifdef PTREE
813192Smckusick 		    nesting--;
823192Smckusick #		endif PTREE
833192Smckusick 		return;
843192Smckusick 	}
853192Smckusick #ifdef OBJ
863192Smckusick 	/*
873192Smckusick 	 * Patch the branch to the
883192Smckusick 	 * entry point of the function
893192Smckusick 	 */
9018347Smckusick 	patch4((PTR_DCL) fp->value[NL_ENTLOC]);
913192Smckusick 	/*
923192Smckusick 	 * Put out the block entrance code and the block name.
933192Smckusick 	 * HDRSZE is the number of bytes of info in the static
943192Smckusick 	 * BEG data area exclusive of the proc name. It is
953192Smckusick 	 * currently defined as:
963192Smckusick 	/*	struct hdr {
973192Smckusick 	/*		long framesze;	/* number of bytes of local vars */
983192Smckusick 	/*		long nargs;	/* number of bytes of arguments */
993192Smckusick 	/*		bool tests;	/* TRUE => perform runtime tests */
1003192Smckusick 	/*		short offset;	/* offset of procedure in source file */
1013192Smckusick 	/*		char name[1];	/* name of active procedure */
1023192Smckusick 	/*	};
1033192Smckusick 	 */
1043192Smckusick #	define HDRSZE (2 * sizeof(long) + sizeof(short) + sizeof(bool))
1053192Smckusick 	var = put(2, ((lenstr(fp->symbol,0) + HDRSZE) << 8)
1063192Smckusick 		| (cbn == 1 && opt('p') == 0 ? O_NODUMP: O_BEG), (long)0);
1073192Smckusick 	    /*
1083192Smckusick 	     *  output the number of bytes of arguments
1093192Smckusick 	     *  this is only checked on formal calls.
1103192Smckusick 	     */
11118347Smckusick 	(void) put(2, O_CASE4, cbn == 1 ? (long)0 : (long)(fp->value[NL_OFFS]-DPOFF2));
1123192Smckusick 	    /*
1133192Smckusick 	     *	Output the runtime test mode for the routine
1143192Smckusick 	     */
11518347Smckusick 	(void) put(2, sizeof(bool) == 2 ? O_CASE2 : O_CASE4, opt('t') ? TRUE : FALSE);
1163192Smckusick 	    /*
1173192Smckusick 	     *	Output line number and routine name
1183192Smckusick 	     */
11918347Smckusick 	(void) put(2, O_CASE2, bundle->stmnt_blck.line_no);
1203192Smckusick 	putstr(fp->symbol, 0);
1213192Smckusick #endif OBJ
1223192Smckusick #ifdef PC
1233192Smckusick 	/*
1243192Smckusick 	 * put out the procedure entry code
1253192Smckusick 	 */
12610671Speter 	eecookie.nlp = fp;
1273192Smckusick 	if ( fp -> class == PROG ) {
1289129Smckusick 		/*
1299129Smckusick 		 *	If there is a label declaration in the main routine
1309129Smckusick 		 *	then there may be a non-local goto to it that does
1319129Smckusick 		 *	not appear in this module. We have to assume that
1329129Smckusick 		 *	such a reference may occur and generate code to
1339129Smckusick 		 *	prepare for it.
1349129Smckusick 		 */
1359129Smckusick 	    if ( parts[ cbn ] & LPRT ) {
1369129Smckusick 		parts[ cbn ] |= ( NONLOCALVAR | NONLOCALGOTO );
1379129Smckusick 	    }
13810671Speter 	    codeformain();
1397917Smckusick 	    ftnno = fp -> value[NL_ENTLOC];
14010671Speter 	    prog_prologue(&eecookie);
14118347Smckusick 	    stabline(bundle->stmnt_blck.line_no);
14218347Smckusick 	    stabfunc(fp, "program", bundle->stmnt_blck.line_no , (long) 0 );
1433192Smckusick 	} else {
1447917Smckusick 	    ftnno = fp -> value[NL_ENTLOC];
14510671Speter 	    fp_prologue(&eecookie);
14618347Smckusick 	    stabline(bundle->stmnt_blck.line_no);
14718347Smckusick 	    stabfunc(fp, fp->symbol, bundle->stmnt_blck.line_no,
14818347Smckusick 		(long)(cbn - 1));
1493192Smckusick 	    for ( p = fp -> chain ; p != NIL ; p = p -> chain ) {
15018347Smckusick 		stabparam( p , p -> value[ NL_OFFS ] , (int) lwidth(p->type));
1513192Smckusick 	    }
1523192Smckusick 	    if ( fp -> class == FUNC ) {
1533192Smckusick 		    /*
1543192Smckusick 		     *	stab the function variable
1553192Smckusick 		     */
1563192Smckusick 		p = fp -> ptr[ NL_FVAR ];
15718347Smckusick 		stablvar( p , p -> value[ NL_OFFS ] , (int) lwidth( p -> type));
1583192Smckusick 	    }
1593192Smckusick 		/*
1603192Smckusick 		 *	stab local variables
1613192Smckusick 		 *	rummage down hash chain links.
1623192Smckusick 		 */
1633192Smckusick 	    for ( i = 0 ; i <= 077 ; i++ ) {
1643192Smckusick 		for ( p = disptab[ i ] ; p != NIL ; p = p->nl_next) {
1653192Smckusick 		    if ( ( p -> nl_block & 037 ) != cbn ) {
1663192Smckusick 			break;
1673192Smckusick 		    }
1683192Smckusick 		    /*
16918346Smckusick 		     *	stab locals (not parameters)
1703192Smckusick 		     */
17118347Smckusick 		    if ( p -> symbol != NIL ) {
17218347Smckusick 			if ( p -> class == VAR && p -> value[ NL_OFFS ] < 0 ) {
17318347Smckusick 			    stablvar( p , p -> value[ NL_OFFS ] ,
17418347Smckusick 				(int) lwidth( p -> type ) );
17518347Smckusick 			} else if ( p -> class == CONST ) {
17618347Smckusick 			    stabconst( p );
17718346Smckusick 			}
1783192Smckusick 		    }
1793192Smckusick 		}
1803192Smckusick 	    }
1813192Smckusick 	}
1823192Smckusick 	stablbrac( cbn );
1833192Smckusick 	    /*
1843192Smckusick 	     *	ask second pass to allocate known locals
1853192Smckusick 	     */
18611337Speter 	putlbracket(ftnno, &sizes[cbn]);
18710671Speter 	fp_entrycode(&eecookie);
1883192Smckusick #endif PC
1893192Smckusick 	if ( monflg ) {
1903192Smckusick 		if ( fp -> value[ NL_CNTR ] != 0 ) {
1913192Smckusick 			inccnt( fp -> value [ NL_CNTR ] );
1923192Smckusick 		}
1933192Smckusick 		inccnt( bodycnts[ fp -> nl_block & 037 ] );
1943192Smckusick 	}
1953192Smckusick 	if (fp->class == PROG) {
1963192Smckusick 		/*
1973192Smckusick 		 * The glorious buffers option.
1983192Smckusick 		 *          0 = don't buffer output
1993192Smckusick 		 *          1 = line buffer output
2003192Smckusick 		 *          2 = 512 byte buffer output
2013192Smckusick 		 */
2023192Smckusick #		ifdef OBJ
2033192Smckusick 		    if (opt('b') != 1)
20418347Smckusick 			    (void) put(1, O_BUFF | opt('b') << 8);
2053192Smckusick #		endif OBJ
2063192Smckusick #		ifdef PC
2073192Smckusick 		    if ( opt( 'b' ) != 1 ) {
20818457Sralph 			putleaf( PCC_ICON , 0 , 0
20918457Sralph 				, PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR ) , "_BUFF" );
21018457Sralph 			putleaf( PCC_ICON , opt( 'b' ) , 0 , PCCT_INT , (char *) 0 );
21118457Sralph 			putop( PCC_CALL , PCCT_INT );
2123192Smckusick 			putdot( filename , line );
2133192Smckusick 		    }
2143192Smckusick #		endif PC
2157953Speter 		inp = 0;
2163192Smckusick 		out = 0;
2173192Smckusick 		for (p = fp->chain; p != NIL; p = p->chain) {
21818347Smckusick 			if (pstrcmp(p->symbol, input->symbol) == 0) {
2193192Smckusick 				inp++;
2203192Smckusick 				continue;
2213192Smckusick 			}
22218347Smckusick 			if (pstrcmp(p->symbol, output->symbol) == 0) {
2233192Smckusick 				out++;
2243192Smckusick 				continue;
2253192Smckusick 			}
2263192Smckusick 			iop = lookup1(p->symbol);
2273192Smckusick 			if (iop == NIL || bn != cbn) {
2283192Smckusick 				error("File %s listed in program statement but not declared", p->symbol);
2293192Smckusick 				continue;
2303192Smckusick 			}
2313192Smckusick 			if (iop->class != VAR) {
2323192Smckusick 				error("File %s listed in program statement but declared as a %s", p->symbol, classes[iop->class]);
2333192Smckusick 				continue;
2343192Smckusick 			}
2353192Smckusick 			if (iop->type == NIL)
2363192Smckusick 				continue;
2373192Smckusick 			if (iop->type->class != FILET) {
2383192Smckusick 				error("File %s listed in program statement but defined as %s",
2393192Smckusick 					p->symbol, nameof(iop->type));
2403192Smckusick 				continue;
2413192Smckusick 			}
2423192Smckusick #			ifdef OBJ
24318347Smckusick 			    (void) put(2, O_CON24, text(iop->type) ? 0 : width(iop->type->type));
2443192Smckusick 			    i = lenstr(p->symbol,0);
24518347Smckusick 			    (void) put(2, O_CON24, i);
24618347Smckusick 			    (void) put(2, O_LVCON, i);
2473192Smckusick 			    putstr(p->symbol, 0);
24818347Smckusick 			    (void) put(2, O_LV | bn<<8+INDX, (int)iop->value[NL_OFFS]);
24918347Smckusick 			    (void) put(1, O_DEFNAME);
2503192Smckusick #			endif OBJ
2513192Smckusick #			ifdef PC
25218457Sralph 			    putleaf( PCC_ICON , 0 , 0
25318457Sralph 				    , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR )
2543192Smckusick 				    , "_DEFNAME" );
2553837Speter 			    putLV( p -> symbol , bn , iop -> value[NL_OFFS] ,
2563837Speter 				    iop -> extra_flags , p2type( iop ) );
2573192Smckusick 			    putCONG( p -> symbol , strlen( p -> symbol )
2583192Smckusick 				    , LREQ );
25918457Sralph 			    putop( PCC_CM , PCCT_INT );
26018457Sralph 			    putleaf( PCC_ICON , strlen( p -> symbol )
26118457Sralph 				    , 0 , PCCT_INT , (char *) 0 );
26218457Sralph 			    putop( PCC_CM , PCCT_INT );
26318457Sralph 			    putleaf( PCC_ICON
2643192Smckusick 				, text(iop->type) ? 0 : width(iop->type->type)
26518457Sralph 				, 0 , PCCT_INT , (char *) 0 );
26618457Sralph 			    putop( PCC_CM , PCCT_INT );
26718457Sralph 			    putop( PCC_CALL , PCCT_INT );
2683192Smckusick 			    putdot( filename , line );
2693192Smckusick #			endif PC
2703192Smckusick 		}
2713192Smckusick 	}
2723192Smckusick 	/*
2733192Smckusick 	 * Process the prog/proc/func body
2743192Smckusick 	 */
27518347Smckusick 	noreach = FALSE;
27618347Smckusick 	line = bundle->stmnt_blck.line_no;
2773192Smckusick 	statlist(blk);
2783192Smckusick #	ifdef PTREE
2793192Smckusick 	    {
2803192Smckusick 		pPointer Body = tCopy( blk );
2813192Smckusick 
2823192Smckusick 		pDEF( PorFHeader[ nesting -- ] ).PorFBody = Body;
2833192Smckusick 	    }
2843192Smckusick #	endif PTREE
2853192Smckusick #	ifdef OBJ
28618347Smckusick 	    if (cbn== 1 && monflg != FALSE) {
28718347Smckusick 		    patchfil((PTR_DCL) (cntpatch - 2), (long)cnts, 2);
28818347Smckusick 		    patchfil((PTR_DCL) (nfppatch - 2), (long)pfcnt, 2);
2893192Smckusick 	    }
2903192Smckusick #	endif OBJ
2913192Smckusick #	ifdef PC
2923192Smckusick 	    if ( fp -> class == PROG && monflg ) {
29318457Sralph 		putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR )
2943192Smckusick 			, "_PMFLUSH" );
29518457Sralph 		putleaf( PCC_ICON , cnts , 0 , PCCT_INT , (char *) 0 );
29618457Sralph 		putleaf( PCC_ICON , pfcnt , 0 , PCCT_INT , (char *) 0 );
29718457Sralph 		putop( PCC_CM , PCCT_INT );
29818457Sralph 		putLV( PCPCOUNT , 0 , 0 , NGLOBAL , PCCT_INT );
29918457Sralph 		putop( PCC_CM , PCCT_INT );
30018457Sralph 		putop( PCC_CALL , PCCT_INT );
3013192Smckusick 		putdot( filename , line );
3023192Smckusick 	    }
3033192Smckusick #	endif PC
3047953Speter 	/*
3057953Speter 	 * Clean up the symbol table displays and check for unresolves
3067953Speter 	 */
3077953Speter 	line = endline;
3083192Smckusick 	if (fp->class == PROG && inp == 0 && (input->nl_flags & (NUSED|NMOD)) != 0) {
3093192Smckusick 		recovered();
3103192Smckusick 		error("Input is used but not defined in the program statement");
3113192Smckusick 	}
3127953Speter 	if (fp->class == PROG && out == 0 && (output->nl_flags & (NUSED|NMOD)) != 0) {
3137953Speter 		recovered();
3147953Speter 		error("Output is used but not defined in the program statement");
3157953Speter 	}
3163192Smckusick 	b = cbn;
3173192Smckusick 	Fp = fp;
31818347Smckusick 	chkref = (syneflg == errcnt[cbn] && opt('w') == 0)?TRUE:FALSE;
3193192Smckusick 	for (i = 0; i <= 077; i++) {
3203192Smckusick 		for (p = disptab[i]; p != NIL && (p->nl_block & 037) == b; p = p->nl_next) {
3213192Smckusick 			/*
3223192Smckusick 			 * Check for variables defined
3233192Smckusick 			 * but not referenced
3243192Smckusick 			 */
3253192Smckusick 			if (chkref && p->symbol != NIL)
3263192Smckusick 			switch (p->class) {
3273192Smckusick 				case FIELD:
3283192Smckusick 					/*
3293192Smckusick 					 * If the corresponding record is
3303192Smckusick 					 * unused, we shouldn't complain about
3313192Smckusick 					 * the fields.
3323192Smckusick 					 */
3333192Smckusick 				default:
3343192Smckusick 					if ((p->nl_flags & (NUSED|NMOD)) == 0) {
3353192Smckusick 						warning();
3363192Smckusick 						nerror("%s %s is neither used nor set", classes[p->class], p->symbol);
3373192Smckusick 						break;
3383192Smckusick 					}
3393192Smckusick 					/*
3403192Smckusick 					 * If a var parameter is either
3413192Smckusick 					 * modified or used that is enough.
3423192Smckusick 					 */
3433192Smckusick 					if (p->class == REF)
3443192Smckusick 						continue;
3453192Smckusick #					ifdef OBJ
3463192Smckusick 					    if ((p->nl_flags & NUSED) == 0) {
3473192Smckusick 						warning();
3483192Smckusick 						nerror("%s %s is never used", classes[p->class], p->symbol);
3493192Smckusick 						break;
3503192Smckusick 					    }
3513192Smckusick #					endif OBJ
3523192Smckusick #					ifdef PC
3533837Speter 					    if (((p->nl_flags & NUSED) == 0) && ((p->extra_flags & NEXTERN) == 0)) {
3543192Smckusick 						warning();
3553192Smckusick 						nerror("%s %s is never used", classes[p->class], p->symbol);
3563192Smckusick 						break;
3573192Smckusick 					    }
3583192Smckusick #					endif PC
3593192Smckusick 					if ((p->nl_flags & NMOD) == 0) {
3603192Smckusick 						warning();
3613192Smckusick 						nerror("%s %s is used but never set", classes[p->class], p->symbol);
3623192Smckusick 						break;
3633192Smckusick 					}
3643192Smckusick 				case LABEL:
3653192Smckusick 				case FVAR:
3663192Smckusick 				case BADUSE:
3673192Smckusick 					break;
3683192Smckusick 			}
3693192Smckusick 			switch (p->class) {
3703192Smckusick 				case BADUSE:
3713192Smckusick 					cp = "s";
37218347Smckusick 					/* This used to say ud_next
37318347Smckusick 					   that is not a member of nl so
37418347Smckusick 					   i changed it to nl_next,
37518347Smckusick 					   which may be wrong */
37618347Smckusick 					if (p->chain->nl_next == NIL)
3773192Smckusick 						cp++;
3783192Smckusick 					eholdnl();
3793192Smckusick 					if (p->value[NL_KINDS] & ISUNDEF)
3803192Smckusick 						nerror("%s undefined on line%s", p->symbol, cp);
3813192Smckusick 					else
3823192Smckusick 						nerror("%s improperly used on line%s", p->symbol, cp);
3833192Smckusick 					pnumcnt = 10;
38418347Smckusick 					pnums((struct udinfo *) p->chain);
3853192Smckusick 					pchr('\n');
3863192Smckusick 					break;
3873192Smckusick 
3883192Smckusick 				case FUNC:
3893192Smckusick 				case PROC:
3903192Smckusick #					ifdef OBJ
3913192Smckusick 					    if ((p->nl_flags & NFORWD))
3923192Smckusick 						nerror("Unresolved forward declaration of %s %s", classes[p->class], p->symbol);
3933192Smckusick #					endif OBJ
3943192Smckusick #					ifdef PC
3953837Speter 					    if ((p->nl_flags & NFORWD) && ((p->extra_flags & NEXTERN) == 0))
3963192Smckusick 						nerror("Unresolved forward declaration of %s %s", classes[p->class], p->symbol);
3973192Smckusick #					endif PC
3983192Smckusick 					break;
3993192Smckusick 
4003192Smckusick 				case LABEL:
4013192Smckusick 					if (p->nl_flags & NFORWD)
4023192Smckusick 						nerror("label %s was declared but not defined", p->symbol);
4033192Smckusick 					break;
4043192Smckusick 				case FVAR:
4053192Smckusick 					if ((p->nl_flags & NMOD) == 0)
4063192Smckusick 						nerror("No assignment to the function variable");
4073192Smckusick 					break;
4083192Smckusick 			}
4093192Smckusick 		}
4103192Smckusick 		/*
4113192Smckusick 		 * Pop this symbol
4123192Smckusick 		 * table slot
4133192Smckusick 		 */
4143192Smckusick 		disptab[i] = p;
4153192Smckusick 	}
4163192Smckusick 
4173192Smckusick #	ifdef OBJ
41818347Smckusick 	    (void) put(1, O_END);
4193192Smckusick #	endif OBJ
4203192Smckusick #	ifdef PC
42110671Speter 	    fp_exitcode(&eecookie);
42210671Speter 	    stabrbrac(cbn);
42310671Speter 	    putrbracket(ftnno);
42410671Speter 	    fp_epilogue(&eecookie);
42510671Speter 	    if (fp -> class != PROG) {
42610671Speter 		fp_formalentry(&eecookie);
4273192Smckusick 	    }
4283192Smckusick 		/*
4293192Smckusick 		 *	declare pcp counters, if any
4303192Smckusick 		 */
4313192Smckusick 	    if ( monflg && fp -> class == PROG ) {
4323192Smckusick 		putprintf( "	.data" , 0 );
43318457Sralph 		aligndot(PCCT_INT);
4343192Smckusick 		putprintf( "	.comm	" , 1 );
4353192Smckusick 		putprintf( PCPCOUNT , 1 );
4363192Smckusick 		putprintf( ",%d" , 0 , ( cnts + 1 ) * sizeof (long) );
4373192Smckusick 		putprintf( "	.text" , 0 );
4383192Smckusick 	    }
4393192Smckusick #	endif PC
4403192Smckusick #ifdef DEBUG
44118347Smckusick 	dumpnl(fp->ptr[2], (int) fp->symbol);
4423192Smckusick #endif
4435654Slinton 
4445654Slinton #ifdef OBJ
4453192Smckusick 	/*
4465654Slinton 	 * save the namelist for the debugger pdx
4475654Slinton 	 */
4485654Slinton 
44918347Smckusick 	savenl(fp->ptr[2], (int) fp->symbol);
4505654Slinton #endif
4515654Slinton 
4525654Slinton 	/*
4533192Smckusick 	 * Restore the
4543192Smckusick 	 * (virtual) name list
4553192Smckusick 	 * position
4563192Smckusick 	 */
4573192Smckusick 	nlfree(fp->ptr[2]);
4583192Smckusick 	/*
4593192Smckusick 	 * Proc/func has been
4603192Smckusick 	 * resolved
4613192Smckusick 	 */
4623192Smckusick 	fp->nl_flags &= ~NFORWD;
4633192Smckusick 	/*
4643192Smckusick 	 * Patch the beg
4653192Smckusick 	 * of the proc/func to
4663192Smckusick 	 * the proper variable size
4673192Smckusick 	 */
4683192Smckusick 	if (Fp == NIL)
4693192Smckusick 		elineon();
4703192Smckusick #	ifdef OBJ
47118347Smckusick 	    patchfil((PTR_DCL) var, leven(-sizes[cbn].om_max), 2);
4723192Smckusick #	endif OBJ
4733192Smckusick 	cbn--;
4743192Smckusick 	if (inpflist(fp->symbol)) {
4753192Smckusick 		opop('l');
4763192Smckusick 	}
4773192Smckusick }
4783363Speter 
4793363Speter #ifdef PC
4803363Speter     /*
4813363Speter      *	construct the long name of a function based on it's static nesting.
4823363Speter      *	into a caller-supplied buffer (that should be about BUFSIZ big).
4833363Speter      */
4843363Speter sextname( buffer , name , level )
4853363Speter     char	buffer[];
4863363Speter     char	*name;
4873363Speter     int		level;
4883363Speter {
4893363Speter     char	*starthere;
4903363Speter     int	i;
4913363Speter 
4923363Speter     starthere = &buffer[0];
4933363Speter     for ( i = 1 ; i < level ; i++ ) {
4943363Speter 	sprintf( starthere , EXTFORMAT , enclosing[ i ] );
4953363Speter 	starthere += strlen( enclosing[ i ] ) + 1;
4963363Speter     }
4973367Speter     sprintf( starthere , EXTFORMAT , name );
4983367Speter     starthere += strlen( name ) + 1;
4993363Speter     if ( starthere >= &buffer[ BUFSIZ ] ) {
5003363Speter 	panic( "sextname" );
5013363Speter     }
5023363Speter }
50310671Speter 
50410671Speter     /*
50510671Speter      *	code for main()
50610671Speter      */
50710671Speter #ifdef vax
50810671Speter 
50910671Speter codeformain()
51010671Speter {
51110671Speter     putprintf("	.text" , 0 );
51210671Speter     putprintf("	.align	1" , 0 );
51310671Speter     putprintf("	.globl	_main" , 0 );
51410671Speter     putprintf("_main:" , 0 );
51510671Speter     putprintf("	.word	0" , 0 );
51610671Speter     if ( opt ( 't' ) ) {
51710671Speter 	putprintf("	pushl	$1" , 0 );
51810671Speter     } else {
51910671Speter 	putprintf("	pushl	$0" , 0 );
52010671Speter     }
52110671Speter     putprintf("	calls	$1,_PCSTART" , 0 );
52210671Speter     putprintf("	movl	4(ap),__argc" , 0 );
52310671Speter     putprintf("	movl	8(ap),__argv" , 0 );
52410671Speter     putprintf("	calls	$0,_program" , 0 );
52510671Speter     putprintf("	pushl	$0" , 0 );
52610671Speter     putprintf("	calls	$1,_PCEXIT" , 0 );
52710671Speter }
52810671Speter 
52910671Speter     /*
53010671Speter      *	prologue for the program.
53110671Speter      *	different because it
53210671Speter      *		doesn't have formal entry point
53310671Speter      */
53410671Speter prog_prologue(eecookiep)
53510671Speter     struct entry_exit_cookie	*eecookiep;
53610671Speter {
53710671Speter     putprintf("	.text" , 0 );
53810671Speter     putprintf("	.align	1" , 0 );
53910671Speter     putprintf("	.globl	_program" , 0 );
54010671Speter     putprintf("_program:" , 0 );
54110716Speter 	/*
54210716Speter 	 *	register save mask
54310716Speter 	 */
54418347Smckusick     eecookiep -> savlabel = (int) getlab();
54518347Smckusick     putprintf("	.word	%s%d", 0, (int) SAVE_MASK_LABEL , eecookiep -> savlabel );
54610671Speter }
54710671Speter 
54810671Speter fp_prologue(eecookiep)
54910671Speter     struct entry_exit_cookie	*eecookiep;
55010671Speter {
55110671Speter 
55210671Speter     sextname( eecookiep -> extname, eecookiep -> nlp -> symbol , cbn - 1 );
55310671Speter     putprintf( "	.text" , 0 );
55410671Speter     putprintf( "	.align	1" , 0 );
55518347Smckusick     putprintf( "	.globl	%s%s", 0, (int) FORMALPREFIX, (int) eecookiep -> extname );
55618347Smckusick     putprintf( "	.globl	%s" , 0 , (int) eecookiep -> extname );
55718347Smckusick     putprintf( "%s:" , 0 , (int) eecookiep -> extname );
55810671Speter 	/*
55910671Speter 	 *	register save mask
56010671Speter 	 */
56118347Smckusick     eecookiep -> savlabel = (int) getlab();
56218347Smckusick     putprintf("	.word	%s%d", 0, (int) SAVE_MASK_LABEL , eecookiep -> savlabel );
56310671Speter }
56410671Speter 
56510671Speter     /*
56610671Speter      *	code before any user code.
56710671Speter      *	or code that is machine dependent.
56810671Speter      */
56910671Speter fp_entrycode(eecookiep)
57010671Speter     struct entry_exit_cookie	*eecookiep;
57110671Speter {
57210714Speter     int	ftnno = eecookiep -> nlp -> value[NL_ENTLOC];
57318347Smckusick     int	proflabel = (int) getlab();
57418347Smckusick     int	setjmp0 = (int) getlab();
57510671Speter 
57610671Speter 	/*
57710671Speter 	 *	top of code;  destination of jump from formal entry code.
57810671Speter 	 */
57918347Smckusick     eecookiep -> toplabel = (int) getlab();
58018347Smckusick     (void) putlab( (char *) eecookiep -> toplabel );
58118347Smckusick     putprintf("	subl2	$%s%d,sp" , 0 , (int) FRAME_SIZE_LABEL, ftnno );
58210671Speter     if ( profflag ) {
58310671Speter 	    /*
58410671Speter 	     *	call mcount for profiling
58510671Speter 	     */
58610671Speter 	putprintf( "	moval	" , 1 );
58718347Smckusick 	putprintf( PREFIXFORMAT , 1 , (int) LABELPREFIX , proflabel );
58810671Speter 	putprintf( ",r0" , 0 );
58910671Speter 	putprintf( "	jsb	mcount" , 0 );
59010671Speter 	putprintf( "	.data" , 0 );
59110671Speter 	putprintf( "	.align	2" , 0 );
59218347Smckusick 	(void) putlab( (char *) proflabel );
59310671Speter 	putprintf( "	.long	0" , 0 );
59410671Speter 	putprintf( "	.text" , 0 );
59510671Speter     }
59610671Speter 	/*
59710671Speter 	 *	if there are nested procedures that access our variables
59810671Speter 	 *	we must save the display.
59910671Speter 	 */
60010671Speter     if ( parts[ cbn ] & NONLOCALVAR ) {
60110671Speter 	    /*
60210671Speter 	     *	save old display
60310671Speter 	     */
60410671Speter 	putprintf( "	movq	%s+%d,%d(%s)" , 0
60518347Smckusick 		, (int) DISPLAYNAME , cbn * sizeof(struct dispsave)
60618347Smckusick 		, DSAVEOFFSET , (int) P2FPNAME );
60710671Speter 	    /*
60810671Speter 	     *	set up new display by saving AP and FP in appropriate
60910671Speter 	     *	slot in display structure.
61010671Speter 	     */
61110671Speter 	putprintf( "	movq	%s,%s+%d" , 0
61218347Smckusick 		, (int) P2APNAME , (int) DISPLAYNAME , cbn * sizeof(struct dispsave) );
61310671Speter     }
61410671Speter 	/*
61510671Speter 	 *	set underflow checking if runtime tests
61610671Speter 	 */
61710671Speter     if ( opt( 't' ) ) {
61810671Speter 	putprintf( "	bispsw	$0xe0" , 0 );
61910671Speter     }
62010671Speter 	/*
62110671Speter 	 *	zero local variables if checking is on
62210671Speter 	 *	by calling blkclr( bytes of locals , starting local address );
62310671Speter 	 */
62410671Speter     if ( opt( 't' ) && ( -sizes[ cbn ].om_max ) > DPOFF1 ) {
62518457Sralph 	putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR )
62610671Speter 		, "_blkclr" );
62718457Sralph 	putLV((char *) 0 , cbn , (int) sizes[ cbn ].om_max , NLOCAL , PCCT_CHAR );
62818457Sralph 	putleaf( PCC_ICON ,  (int) (( -sizes[ cbn ].om_max ) - DPOFF1)
62918457Sralph 		, 0 , PCCT_INT ,(char *) 0 );
63018457Sralph 	putop( PCC_CM , PCCT_INT );
63118457Sralph 	putop( PCC_CALL , PCCT_INT );
63210671Speter 	putdot( filename , line );
63310671Speter     }
63410671Speter 	/*
63510671Speter 	 *  set up goto vector if non-local goto to this frame
63610671Speter 	 */
63710671Speter     if ( parts[ cbn ] & NONLOCALGOTO ) {
63818457Sralph 	putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR )
63910671Speter 		, "_setjmp" );
64018457Sralph 	putLV( (char *) 0 , cbn , GOTOENVOFFSET , NLOCAL , PCCTM_PTR|PCCT_STRTY );
64118457Sralph 	putop( PCC_CALL , PCCT_INT );
64218457Sralph 	putleaf( PCC_ICON , 0 , 0 , PCCT_INT , (char *) 0 );
64318457Sralph 	putop( PCC_NE , PCCT_INT );
64418457Sralph 	putleaf( PCC_ICON , setjmp0 , 0 , PCCT_INT , (char *) 0 );
64518457Sralph 	putop( PCC_CBRANCH , PCCT_INT );
64610671Speter 	putdot( filename , line );
64710671Speter 	    /*
64810671Speter 	     *	on non-local goto, setjmp returns with address to
64910671Speter 	     *	be branched to.
65010671Speter 	     */
65110671Speter 	putprintf( "	jmp	(r0)" , 0 );
65218347Smckusick 	(void) putlab((char *) setjmp0);
65310671Speter     }
65410671Speter }
65510671Speter 
65610671Speter fp_exitcode(eecookiep)
65710671Speter     struct entry_exit_cookie	*eecookiep;
65810671Speter {
65910671Speter 	/*
66010671Speter 	 *	if there were file variables declared at this level
66110671Speter 	 *	call PCLOSE( ap ) to clean them up.
66210671Speter 	 */
66310671Speter     if ( dfiles[ cbn ] ) {
66418457Sralph 	putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR )
66510671Speter 		, "_PCLOSE" );
66618457Sralph 	putleaf( PCC_REG , 0 , P2AP , PCCM_ADDTYPE( PCCT_CHAR , PCCTM_PTR ) , (char *) 0 );
66718457Sralph 	putop( PCC_CALL , PCCT_INT );
66810671Speter 	putdot( filename , line );
66910671Speter     }
67010671Speter 	/*
67110671Speter 	 *	if this is a function,
67210671Speter 	 *	the function variable is the return value.
67310671Speter 	 *	if it's a scalar valued function, return scalar,
67410671Speter 	 *	else, return a pointer to the structure value.
67510671Speter 	 */
67610671Speter     if ( eecookiep-> nlp -> class == FUNC ) {
67710671Speter 	struct nl	*fvar = eecookiep-> nlp -> ptr[ NL_FVAR ];
67810671Speter 	long		fvartype = p2type( fvar -> type );
67910671Speter 	long		label;
68010671Speter 	char		labelname[ BUFSIZ ];
68110671Speter 
68210671Speter 	switch ( classify( fvar -> type ) ) {
68310671Speter 	    case TBOOL:
68410671Speter 	    case TCHAR:
68510671Speter 	    case TINT:
68610671Speter 	    case TSCAL:
68710671Speter 	    case TDOUBLE:
68810671Speter 	    case TPTR:
68910671Speter 		putRV( fvar -> symbol , ( fvar -> nl_block ) & 037 ,
69010671Speter 			fvar -> value[ NL_OFFS ] ,
69110671Speter 			fvar -> extra_flags ,
69218347Smckusick 			(int) fvartype );
69318457Sralph 		putop( PCC_FORCE , (int) fvartype );
69410671Speter 		break;
69510671Speter 	    default:
69618347Smckusick 		label = (int) getlab();
69710671Speter 		sprintf( labelname , PREFIXFORMAT , LABELPREFIX , label );
69810671Speter 		putprintf( "	.data" , 0 );
69910671Speter 		aligndot(A_STRUCT);
70010671Speter 		putprintf( "	.lcomm	%s,%d" , 0 ,
70118347Smckusick 			    (int) labelname , (int) lwidth( fvar -> type ) );
70210671Speter 		putprintf( "	.text" , 0 );
70318457Sralph 		putleaf( PCC_NAME , 0 , 0 , (int) fvartype , labelname );
70410671Speter 		putLV( fvar -> symbol , ( fvar -> nl_block ) & 037 ,
70510671Speter 			fvar -> value[ NL_OFFS ] ,
70610671Speter 			fvar -> extra_flags ,
70718347Smckusick 			(int) fvartype );
70818457Sralph 		putstrop( PCC_STASG , (int) PCCM_ADDTYPE(fvartype, PCCTM_PTR) ,
70918347Smckusick 			(int) lwidth( fvar -> type ) ,
71010671Speter 			align( fvar -> type ) );
71110671Speter 		putdot( filename , line );
71218457Sralph 		putleaf( PCC_ICON , 0 , 0 , (int) PCCM_ADDTYPE(fvartype, PCCTM_PTR), labelname );
71318457Sralph 		putop( PCC_FORCE , (int) PCCM_ADDTYPE(fvartype, PCCTM_PTR) );
71410671Speter 		break;
71510671Speter 	}
71610671Speter 	putdot( filename , line );
71710671Speter     }
71810671Speter 	/*
71910671Speter 	 *	if there are nested procedures we must save the display.
72010671Speter 	 */
72110671Speter     if ( parts[ cbn ] & NONLOCALVAR ) {
72210671Speter 	    /*
72310671Speter 	     *	restore old display entry from save area
72410671Speter 	     */
72510671Speter 	putprintf( "	movq	%d(%s),%s+%d" , 0
72618347Smckusick 	    , DSAVEOFFSET , (int) P2FPNAME
72718347Smckusick 	    , (int) DISPLAYNAME , cbn * sizeof(struct dispsave) );
72810671Speter     }
72910671Speter }
73010671Speter 
73110671Speter fp_epilogue(eecookiep)
73210671Speter     struct entry_exit_cookie	*eecookiep;
73310671Speter {
73418346Smckusick     stabline(line);
73510671Speter     putprintf("	ret" , 0 );
73610671Speter 	/*
73710671Speter 	 *	set the register save mask.
73810671Speter 	 */
73910671Speter     putprintf("	.set	%s%d,0x%x", 0,
74018347Smckusick 		(int) SAVE_MASK_LABEL, eecookiep -> savlabel, savmask());
74110671Speter }
74210671Speter 
74310671Speter fp_formalentry(eecookiep)
74410671Speter     struct entry_exit_cookie	*eecookiep;
74510671Speter {
74610671Speter 
74711857Speter     putprintf("	.align 1", 0);
74818347Smckusick     putprintf("%s%s:" , 0 , (int) FORMALPREFIX , (int) eecookiep -> extname );
74918347Smckusick     putprintf("	.word	%s%d", 0, (int) SAVE_MASK_LABEL, eecookiep -> savlabel );
75018457Sralph     putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR ) , "_FCALL" );
75118347Smckusick     putRV((char *) 0 , cbn ,
75210671Speter 	eecookiep -> nlp -> value[ NL_OFFS ] + sizeof( struct formalrtn * ) ,
75318457Sralph 	NPARAM , PCCTM_PTR | PCCT_STRTY );
75418457Sralph     putRV((char *) 0, cbn, eecookiep -> nlp -> value[NL_OFFS], NPARAM, PCCTM_PTR|PCCT_STRTY);
75518457Sralph     putop( PCC_CM , PCCT_INT );
75618457Sralph     putop( PCC_CALL , PCCT_INT );
75710671Speter     putdot( filename , line );
75818347Smckusick     putjbr( (long) eecookiep -> toplabel );
75910671Speter }
76010671Speter #endif vax
76110671Speter 
76210671Speter #ifdef mc68000
76310671Speter 
76410671Speter codeformain()
76510671Speter {
76610671Speter     putprintf("	.text", 0);
76710671Speter     putprintf("	.globl	_main", 0);
76810671Speter     putprintf("_main:", 0);
76910671Speter     putprintf("	link	%s,#0", 0, P2FPNAME);
77010671Speter     if (opt('t')) {
77110671Speter 	putprintf("	pea	1", 0);
77210671Speter     } else {
77310671Speter 	putprintf("	pea	0", 0);
77410671Speter     }
77510671Speter     putprintf("	jbsr	_PCSTART", 0);
77610671Speter     putprintf("	addql	#4,sp", 0);
77710671Speter     putprintf("	movl	%s@(8),__argc", 0, P2FPNAME);
77810671Speter     putprintf("	movl	%s@(12),__argv", 0, P2FPNAME);
77910671Speter     putprintf("	jbsr	_program", 0);
78010671Speter     putprintf("	pea	0", 0);
78110671Speter     putprintf("	jbsr	_PCEXIT", 0);
78210671Speter }
78310671Speter 
78410671Speter prog_prologue(eecookiep)
78510671Speter     struct entry_exit_cookie	*eecookiep;
78610671Speter {
78710671Speter     int	ftnno = eecookiep -> nlp -> value[NL_ENTLOC];
78810671Speter 
78910671Speter     putprintf("	.text", 0);
79010671Speter     putprintf("	.globl	_program", 0);
79110671Speter     putprintf("_program:", 0);
79210671Speter     putprintf("	link	%s,#0", 0, P2FPNAME);
79310671Speter     putprintf("	addl	#-%s%d,sp", 0, FRAME_SIZE_LABEL, ftnno);
79410671Speter 	/* touch new end of stack, to break more stack space */
79510671Speter     putprintf("	tstb	sp@(-%s%d)", 0, PAGE_BREAK_LABEL, ftnno);
79610671Speter     putprintf("	moveml	#%s%d,sp@", 0, SAVE_MASK_LABEL, ftnno);
79710671Speter }
79810671Speter 
79910671Speter fp_prologue(eecookiep)
80010671Speter     struct entry_exit_cookie	*eecookiep;
80110671Speter {
80210671Speter     int		ftnno = eecookiep -> nlp -> value[NL_ENTLOC];
80310671Speter 
80410671Speter     sextname(eecookiep -> extname, eecookiep -> nlp -> symbol, cbn - 1);
80510671Speter     putprintf("	.text", 0);
80610671Speter     putprintf("	.globl	%s%s", 0, FORMALPREFIX, eecookiep -> extname);
80710671Speter     putprintf("	.globl	%s", 0, eecookiep -> extname);
80810671Speter     putprintf("%s:", 0, eecookiep -> extname);
80910671Speter     putprintf("	link	%s,#0", 0, P2FPNAME);
81010671Speter     putprintf("	addl	#-%s%d,sp", 0, FRAME_SIZE_LABEL, ftnno);
81110671Speter 	/* touch new end of stack, to break more stack space */
81210671Speter     putprintf("	tstb	sp@(-%s%d)", 0, PAGE_BREAK_LABEL, ftnno);
81310671Speter     putprintf("	moveml	#%s%d,sp@", 0, SAVE_MASK_LABEL, ftnno);
81410671Speter }
81510671Speter 
81610671Speter fp_entrycode(eecookiep)
81710671Speter     struct entry_exit_cookie	*eecookiep;
81810671Speter {
81918347Smckusick     char *proflabel = getlab();
82018347Smckusick     char *setjmp0 = getlab();
82110671Speter 
82210671Speter 	/*
82310671Speter 	 *	fill in the label cookie
82410671Speter 	 */
82510671Speter     eecookiep -> toplabel = getlab();
82618347Smckusick     (void) putlab(eecookiep -> toplabel);
82710671Speter 	/*
82810671Speter 	 *	call mcount if we are profiling.
82910671Speter 	 */
83010671Speter     if ( profflag ) {
83110671Speter 	putprintf("	movl	#%s%d,a0", 0, LABELPREFIX,  proflabel);
83210671Speter 	putprintf("	jsr	mcount", 0);
83310671Speter 	putprintf("	.data", 0);
83410671Speter 	putprintf("	.even", 0);
83518347Smckusick 	(void) putlab(proflabel);
83610671Speter 	putprintf("	.long	0", 0);
83710671Speter 	putprintf("	.text", 0);
83810671Speter     }
83910671Speter 	/*
84010671Speter 	 *	if there are nested procedures that access our variables
84110671Speter 	 *	we must save the display
84210671Speter 	 */
84310671Speter     if (parts[cbn] & NONLOCALVAR) {
84410671Speter 	    /*
84510671Speter 	     *	save the old display
84610671Speter 	     */
84710671Speter 	putprintf("	movl	%s+%d,%s@(%d)", 0,
84810671Speter 		    DISPLAYNAME, cbn * sizeof(struct dispsave),
84910671Speter 		    P2FPNAME, DSAVEOFFSET);
85010671Speter 	    /*
85110671Speter 	     *	set up the new display by saving the framepointer
85210671Speter 	     *	in the display structure.
85310671Speter 	     */
85410671Speter 	putprintf("	movl	%s,%s+%d", 0,
85510671Speter 		    P2FPNAME, DISPLAYNAME, cbn * sizeof(struct dispsave));
85610671Speter     }
85710671Speter 	/*
85810671Speter 	 *	zero local variables if checking is on
85910671Speter 	 *	by calling blkclr( bytes of locals , starting local address );
86010671Speter 	 */
86110671Speter     if ( opt( 't' ) && ( -sizes[ cbn ].om_max ) > DPOFF1 ) {
86218457Sralph 	putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR )
86310671Speter 		, "_blkclr" );
86418457Sralph 	putLV( 0 , cbn , sizes[ cbn ].om_max , NLOCAL , PCCT_CHAR );
86518457Sralph 	putleaf( PCC_ICON ,  ( -sizes[ cbn ].om_max ) - DPOFF1
86618457Sralph 		, 0 , PCCT_INT , 0 );
86718457Sralph 	putop( PCC_CM , PCCT_INT );
86818457Sralph 	putop( PCC_CALL , PCCT_INT );
86910671Speter 	putdot( filename , line );
87010671Speter     }
87110671Speter 	/*
87210671Speter 	 *  set up goto vector if non-local goto to this frame
87310671Speter 	 */
87410671Speter     if ( parts[ cbn ] & NONLOCALGOTO ) {
87518457Sralph 	putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR )
87610671Speter 		, "_setjmp" );
87718457Sralph 	putLV( 0 , cbn , GOTOENVOFFSET , NLOCAL , PCCTM_PTR|PCCT_STRTY );
87818457Sralph 	putop( PCC_CALL , PCCT_INT );
87918457Sralph 	putleaf( PCC_ICON , 0 , 0 , PCCT_INT , 0 );
88018457Sralph 	putop( PCC_NE , PCCT_INT );
88118457Sralph 	putleaf( PCC_ICON , setjmp0 , 0 , PCCT_INT , 0 );
88218457Sralph 	putop( PCC_CBRANCH , PCCT_INT );
88310671Speter 	putdot( filename , line );
88410671Speter 	    /*
88510671Speter 	     *	on non-local goto, setjmp returns with address to
88610671Speter 	     *	be branched to.
88710671Speter 	     */
88810671Speter 	putprintf("	movl	d0,a0", 0);
88910671Speter 	putprintf("	jmp	a0@", 0);
89018347Smckusick 	(void) putlab(setjmp0);
89110671Speter     }
89210671Speter }
89310671Speter 
89410671Speter fp_exitcode(eecookiep)
89510671Speter     struct entry_exit_cookie	*eecookiep;
89610671Speter {
89710671Speter 	/*
89810671Speter 	 *	if there were file variables declared at this level
89910671Speter 	 *	call PCLOSE( ap ) to clean them up.
90010671Speter 	 */
90110671Speter     if ( dfiles[ cbn ] ) {
90218457Sralph 	putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR )
90310671Speter 		, "_PCLOSE" );
90418457Sralph 	putleaf( PCC_REG , 0 , P2AP , PCCM_ADDTYPE( PCCT_CHAR , PCCTM_PTR ) , 0 );
90518457Sralph 	putop( PCC_CALL , PCCT_INT );
90610671Speter 	putdot( filename , line );
90710671Speter     }
90810671Speter 	/*
90910671Speter 	 *	if this is a function,
91010671Speter 	 *	the function variable is the return value.
91110671Speter 	 *	if it's a scalar valued function, return scalar,
91210671Speter 	 *	else, return a pointer to the structure value.
91310671Speter 	 */
91410671Speter     if ( eecookiep -> nlp -> class == FUNC ) {
91510671Speter 	struct nl	*fvar = eecookiep -> nlp -> ptr[ NL_FVAR ];
91610671Speter 	long		fvartype = p2type( fvar -> type );
91718347Smckusick 	char		*label;
91810671Speter 	char		labelname[ BUFSIZ ];
91910671Speter 
92010671Speter 	switch ( classify( fvar -> type ) ) {
92110671Speter 	    case TBOOL:
92210671Speter 	    case TCHAR:
92310671Speter 	    case TINT:
92410671Speter 	    case TSCAL:
92510671Speter 	    case TDOUBLE:
92610671Speter 	    case TPTR:
92710671Speter 		putRV( fvar -> symbol , ( fvar -> nl_block ) & 037 ,
92810671Speter 			fvar -> value[ NL_OFFS ] ,
92910671Speter 			fvar -> extra_flags ,
93010671Speter 			fvartype );
93118457Sralph 		putop( PCC_FORCE , fvartype );
93210671Speter 		break;
93310671Speter 	    default:
93410671Speter 		label = getlab();
93510671Speter 		sprintf( labelname , PREFIXFORMAT , LABELPREFIX , label );
93610671Speter 		putprintf("	.lcomm	%s,%d", 0,
93710671Speter 			labelname, lwidth(fvar -> type));
93818457Sralph 		putleaf( PCC_NAME , 0 , 0 , fvartype , labelname );
93910671Speter 		putLV( fvar -> symbol , ( fvar -> nl_block ) & 037 ,
94010671Speter 			fvar -> value[ NL_OFFS ] ,
94110671Speter 			fvar -> extra_flags ,
94210671Speter 			fvartype );
94318457Sralph 		putstrop( PCC_STASG , PCCM_ADDTYPE(fvartype, PCCTM_PTR) ,
94411857Speter 			lwidth( fvar -> type ) ,
94510671Speter 			align( fvar -> type ) );
94610671Speter 		putdot( filename , line );
94718457Sralph 		putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE(fvartype, PCCTM_PTR), labelname );
94818457Sralph 		putop( PCC_FORCE , PCCM_ADDTYPE(fvartype, PCCTM_PTR) );
94910671Speter 		break;
95010671Speter 	}
95110671Speter 	putdot( filename , line );
95210671Speter     }
95310671Speter 	/*
95410671Speter 	 *	if we saved a display, we must restore it.
95510671Speter 	 */
95610671Speter     if ( parts[ cbn ] & NONLOCALVAR ) {
95710671Speter 	    /*
95810671Speter 	     *	restore old display entry from save area
95910671Speter 	     */
96010671Speter 	putprintf("	movl	%s@(%d),%s+%d", 0,
96110671Speter 		    P2FPNAME, DSAVEOFFSET,
96210671Speter 		    DISPLAYNAME, cbn * sizeof(struct dispsave));
96310671Speter     }
96410671Speter }
96510671Speter 
96610671Speter fp_epilogue(eecookiep)
96710671Speter     struct entry_exit_cookie	*eecookiep;
96810671Speter {
96910671Speter     /*
97010671Speter      *	all done by the second pass.
97110671Speter      */
97210671Speter }
97310671Speter 
97410671Speter fp_formalentry(eecookiep)
97510671Speter     struct entry_exit_cookie	*eecookiep;
97610671Speter {
97710671Speter     putprintf( "%s%s:" , 0 , FORMALPREFIX , eecookiep -> extname );
97810671Speter     putprintf("	link	%s,#0", 0, P2FPNAME);
97910671Speter     putprintf("	addl	#-%s%d,sp", 0, FRAME_SIZE_LABEL, ftnno);
98010671Speter 	/* touch new end of stack, to break more stack space */
98110671Speter     putprintf("	tstb	sp@(-%s%d)", 0, PAGE_BREAK_LABEL, ftnno);
98210671Speter     putprintf("	moveml	#%s%d,sp@", 0, SAVE_MASK_LABEL, ftnno);
98318457Sralph     putleaf( PCC_ICON , 0 , 0 , PCCM_ADDTYPE( PCCTM_FTN | PCCT_INT , PCCTM_PTR ) , "_FCALL" );
98410671Speter     putRV( 0 , cbn ,
98510671Speter 	eecookiep -> nlp -> value[ NL_OFFS ] + sizeof( struct formalrtn * ) ,
98618457Sralph 	NPARAM , PCCTM_PTR | PCCT_STRTY );
98718457Sralph     putRV(0, cbn, eecookiep -> nlp -> value[NL_OFFS], NPARAM, PCCTM_PTR|PCCT_STRTY);
98818457Sralph     putop( PCC_CM , PCCT_INT );
98918457Sralph     putop( PCC_CALL , PCCT_INT );
99010671Speter     putdot( filename , line );
99110671Speter     putjbr( eecookiep -> toplabel );
99210671Speter }
99310671Speter #endif mc68000
9943363Speter #endif PC
995