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