xref: /csrg-svn/usr.bin/pascal/pdx/sym/print.c (revision 5523)
1 /* Copyright (c) 1982 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)print.c 1.1 01/18/82";
4 
5 /*
6  * Routines to print out symbols.
7  */
8 
9 #include "defs.h"
10 #include "sym.h"
11 #include "process.h"
12 #include "tree.h"
13 #include "runtime.h"
14 #include "classes.h"
15 #include "sym.rep"
16 #include "process/process.rep"
17 
18 /*
19  * Note the entry of the given block, unless it's the main program.
20  */
21 
22 printentry(s)
23 SYM *s;
24 {
25 	if (s != program) {
26 		printf("\nentering %s %s\n", classname(s), s->symbol);
27 	}
28 }
29 
30 /*
31  * Note the exit of the given block
32  */
33 
34 printexit(s)
35 SYM *s;
36 {
37 	if (s != program) {
38 		printf("leaving %s %s\n\n", classname(s), s->symbol);
39 	}
40 }
41 
42 /*
43  * Note the call of s from t.
44  */
45 
46 printcall(s, t)
47 SYM *s, *t;
48 {
49 	printf("calling %s", s->symbol);
50 	printparams(s, NIL);
51 	printf(" from %s %s\n", classname(t), t->symbol);
52 }
53 
54 /*
55  * Note the return from s.  If s is a function, print the value
56  * it is returning.  This is somewhat painful, since the function
57  * has actually just returned.
58  */
59 
60 printrtn(s)
61 SYM *s;
62 {
63 	register SYM *t;
64 	register int len;
65 
66 	printf("returning ");
67 	if (s->class == FUNC) {
68 		len = size(s->type);
69 		dread(sp, process->sp, len);
70 		sp += len;
71 		printval(s->type);
72 		putchar(' ');
73 	}
74 	printf("from %s\n", s->symbol);
75 }
76 
77 /*
78  * Print the values of the parameters of the given procedure or function.
79  * The frame distinguishes recursive instances of a procedure.
80  */
81 
82 printparams(f, frame)
83 SYM *f;
84 FRAME *frame;
85 {
86 	SYM *param;
87 
88 	for (param = f->chain; param != NIL; param = param->chain) {
89 		if (param == f->chain) {
90 			printf("(");
91 		}
92 		printv(param, frame);
93 		if (param->chain != NIL) {
94 			printf(", ");
95 		} else {
96 			printf(")");
97 		}
98 	}
99 }
100 
101 /*
102  * Print the name and value of a variable.
103  */
104 
105 printv(s, frame)
106 SYM *s;
107 FRAME *frame;
108 {
109 	ADDRESS addr;
110 	int len;
111 
112 	if (s->class == REF) {
113 		dread(&addr, address(s, frame), sizeof(ADDRESS));
114 		len = size(s->type);
115 	} else {
116 		addr = address(s, frame);
117 		len = size(s);
118 	}
119 	dread(sp, addr, len);
120 	sp += len;
121 	printf("%s = ", s->symbol);
122 	if (s->class == REF || s->class == VAR) {
123 		printval(s->type);
124 	} else {
125 		printval(s);
126 	}
127 }
128 
129 /*
130  * Print the fully specified variable that is described by the given identifer.
131  */
132 
133 printwhich(s)
134 SYM *s;
135 {
136 	printouter(s->func);
137 	printf("%s", s->symbol);
138 }
139 
140 LOCAL printouter(s)
141 SYM *s;
142 {
143 	if (s->func != NIL) {
144 		printouter(s->func);
145 	}
146 	printf("%s.", s->symbol);
147 }
148