xref: /csrg-svn/usr.bin/pascal/pdx/sym/print.c (revision 62149)
148093Sbostic /*-
2*62149Sbostic  * Copyright (c) 1980, 1993
3*62149Sbostic  *	The Regents of the University of California.  All rights reserved.
448093Sbostic  *
548093Sbostic  * %sccs.include.redist.c%
622525Sdist  */
75523Slinton 
822525Sdist #ifndef lint
9*62149Sbostic static char sccsid[] = "@(#)print.c	8.1 (Berkeley) 06/06/93";
1048093Sbostic #endif /* not lint */
1148093Sbostic 
125523Slinton /*
135523Slinton  * Routines to print out symbols.
145523Slinton  */
155523Slinton 
165523Slinton #include "defs.h"
175523Slinton #include "sym.h"
185523Slinton #include "process.h"
195523Slinton #include "tree.h"
205523Slinton #include "runtime.h"
215523Slinton #include "classes.h"
225523Slinton #include "sym.rep"
235523Slinton #include "process/process.rep"
245523Slinton 
255523Slinton /*
265523Slinton  * Note the entry of the given block, unless it's the main program.
275523Slinton  */
285523Slinton 
printentry(s)295523Slinton printentry(s)
305523Slinton SYM *s;
315523Slinton {
325523Slinton 	if (s != program) {
335523Slinton 		printf("\nentering %s %s\n", classname(s), s->symbol);
345523Slinton 	}
355523Slinton }
365523Slinton 
375523Slinton /*
385523Slinton  * Note the exit of the given block
395523Slinton  */
405523Slinton 
printexit(s)415523Slinton printexit(s)
425523Slinton SYM *s;
435523Slinton {
445523Slinton 	if (s != program) {
455523Slinton 		printf("leaving %s %s\n\n", classname(s), s->symbol);
465523Slinton 	}
475523Slinton }
485523Slinton 
495523Slinton /*
505523Slinton  * Note the call of s from t.
515523Slinton  */
525523Slinton 
printcall(s,t)535523Slinton printcall(s, t)
545523Slinton SYM *s, *t;
555523Slinton {
565523Slinton 	printf("calling %s", s->symbol);
575523Slinton 	printparams(s, NIL);
585523Slinton 	printf(" from %s %s\n", classname(t), t->symbol);
595523Slinton }
605523Slinton 
615523Slinton /*
625523Slinton  * Note the return from s.  If s is a function, print the value
635523Slinton  * it is returning.  This is somewhat painful, since the function
645523Slinton  * has actually just returned.
655523Slinton  */
665523Slinton 
printrtn(s)675523Slinton printrtn(s)
685523Slinton SYM *s;
695523Slinton {
705523Slinton 	register int len;
715523Slinton 
725523Slinton 	printf("returning ");
735523Slinton 	if (s->class == FUNC) {
745523Slinton 		len = size(s->type);
755523Slinton 		dread(sp, process->sp, len);
765523Slinton 		sp += len;
7730850Smckusick #ifdef tahoe
7830850Smckusick 		alignstack();
7930850Smckusick #endif
805523Slinton 		printval(s->type);
815523Slinton 		putchar(' ');
825523Slinton 	}
835523Slinton 	printf("from %s\n", s->symbol);
845523Slinton }
855523Slinton 
865523Slinton /*
875523Slinton  * Print the values of the parameters of the given procedure or function.
885523Slinton  * The frame distinguishes recursive instances of a procedure.
895523Slinton  */
905523Slinton 
printparams(f,frame)915523Slinton printparams(f, frame)
925523Slinton SYM *f;
935523Slinton FRAME *frame;
945523Slinton {
955523Slinton 	SYM *param;
965523Slinton 
975523Slinton 	for (param = f->chain; param != NIL; param = param->chain) {
985523Slinton 		if (param == f->chain) {
995523Slinton 			printf("(");
1005523Slinton 		}
1015523Slinton 		printv(param, frame);
1025523Slinton 		if (param->chain != NIL) {
1035523Slinton 			printf(", ");
1045523Slinton 		} else {
1055523Slinton 			printf(")");
1065523Slinton 		}
1075523Slinton 	}
1085523Slinton }
1095523Slinton 
1105523Slinton /*
1115523Slinton  * Print the name and value of a variable.
1125523Slinton  */
1135523Slinton 
printv(s,frame)1145523Slinton printv(s, frame)
1155523Slinton SYM *s;
1165523Slinton FRAME *frame;
1175523Slinton {
1185523Slinton 	ADDRESS addr;
1195523Slinton 	int len;
1205523Slinton 
1215523Slinton 	if (s->class == REF) {
1225523Slinton 		dread(&addr, address(s, frame), sizeof(ADDRESS));
1235523Slinton 		len = size(s->type);
1245523Slinton 	} else {
1255523Slinton 		addr = address(s, frame);
1265523Slinton 		len = size(s);
1275523Slinton 	}
1285523Slinton 	printf("%s = ", s->symbol);
1295564Slinton 	if (!rpush(addr, len)) {
1305564Slinton 		printf("*** expression too large ***");
1315523Slinton 	} else {
1325564Slinton 		if (s->class == REF || s->class == VAR) {
1335564Slinton 			printval(s->type);
1345564Slinton 		} else {
1355564Slinton 			printval(s);
1365564Slinton 		}
1375523Slinton 	}
1385523Slinton }
1395523Slinton 
1405523Slinton /*
1415523Slinton  * Print the fully specified variable that is described by the given identifer.
1425523Slinton  */
1435523Slinton 
printwhich(s)1445523Slinton printwhich(s)
1455523Slinton SYM *s;
1465523Slinton {
1475523Slinton 	printouter(s->func);
1485523Slinton 	printf("%s", s->symbol);
1495523Slinton }
1505523Slinton 
printouter(s)1515523Slinton LOCAL printouter(s)
1525523Slinton SYM *s;
1535523Slinton {
1545523Slinton 	if (s->func != NIL) {
1555523Slinton 		printouter(s->func);
1565523Slinton 	}
1575523Slinton 	printf("%s.", s->symbol);
1585523Slinton }
159