add sextname() to make up long external names for things.
[unix-history] / usr / src / usr.bin / pascal / src / stab.c
CommitLineData
b721c131
PK
1/* Copyright (c) 1980 Regents of the University of California */
2
078a6e08 3static char sccsid[] = "@(#)stab.c 1.6 %G%";
c6ae69c6
PK
4
5 /*
b721c131
PK
6 * procedures to put out sdb symbol table information.
7 * and stabs for separate compilation type checking.
8 * these use the new .stabs, .stabn, and .stabd directives
c6ae69c6
PK
9 */
10
c6ae69c6
PK
11#include "whoami.h"
12#ifdef PC
13 /* and the rest of the file */
14# include "0.h"
15# include <stab.h>
16
99f6998f
PK
17 /*
18 * additional symbol definition for <stab.h>
19 * that is used by the separate compilation facility --
20 * eventually, <stab.h> should be updated to include this
21 */
c6ae69c6 22
99f6998f 23# include "pstab.h"
c6ae69c6
PK
24# include "pc.h"
25
b721c131
PK
26 /*
27 * absolute value: line numbers are negative if error recovery.
28 */
29#define ABS( x ) ( x < 0 ? -x : x )
30
c6ae69c6 31 /*
c5e061f2 32 * global variables
c6ae69c6 33 */
c5e061f2 34stabgvar( name , type , offset , length , line )
c6ae69c6
PK
35 char *name;
36 int type;
c6ae69c6
PK
37 int offset;
38 int length;
b721c131 39 int line;
c6ae69c6 40 {
c6ae69c6 41
b721c131
PK
42 /*
43 * for separate compilation
44 */
c5e061f2
PK
45 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0
46 , name , N_PC , N_PGVAR , ABS( line ) );
b721c131
PK
47 /*
48 * for sdb
49 */
c6ae69c6
PK
50 if ( ! opt('g') ) {
51 return;
52 }
53 putprintf( " .stabs \"" , 1 );
54 putprintf( NAMEFORMAT , 1 , name );
c5e061f2 55 putprintf( "\",0x%x,0,0x%x,0" , 0 , N_GSYM , type );
c6ae69c6
PK
56 putprintf( " .stabs \"" , 1 );
57 putprintf( NAMEFORMAT , 1 , name );
b721c131 58 putprintf( "\",0x%x,0,0,0x%x" , 0 , N_LENG , length );
c5e061f2
PK
59}
60
61 /*
62 * local variables
63 */
64stablvar( name , type , level , offset , length )
65 char *name;
66 int type;
67 int level;
68 int offset;
69 int length;
70 {
c6ae69c6 71
c5e061f2
PK
72 if ( ! opt('g') ) {
73 return;
74 }
75 putprintf( " .stabs \"" , 1 );
76 putprintf( NAMEFORMAT , 1 , name );
77 putprintf( "\",0x%x,0,0x%x,0x%x" , 0 , N_LSYM , type , -offset );
78 putprintf( " .stabs \"" , 1 );
79 putprintf( NAMEFORMAT , 1 , name );
80 putprintf( "\",0x%x,0,0,0x%x" , 0 , N_LENG , length );
c6ae69c6
PK
81}
82
83
84 /*
85 * parameters
86 */
87stabparam( name , type , offset , length )
88 char *name;
89 int type;
90 int offset;
91 int length;
92 {
93
94 if ( ! opt('g') ) {
95 return;
96 }
97 putprintf( " .stabs \"" , 1 );
98 putprintf( NAMEFORMAT , 1 , name );
b721c131 99 putprintf( "\",0x%x,0,0x%x,0x%x" , 0 , N_PSYM , type , offset );
c6ae69c6
PK
100 putprintf( " .stabs \"" , 1 );
101 putprintf( NAMEFORMAT , 1 , name );
b721c131 102 putprintf( "\",0x%x,0,0,0x%x" , 0 , N_LENG , length );
c6ae69c6
PK
103 }
104
105 /*
106 * fields
107 */
108stabfield( name , type , offset , length )
109 char *name;
110 int type;
111 int offset;
112 int length;
113 {
114
115 if ( ! opt('g') ) {
116 return;
117 }
118 putprintf( " .stabs \"" , 1 );
119 putprintf( NAMEFORMAT , 1 , name );
b721c131 120 putprintf( "\",0x%x,0,0x%x,0x%x" , 0 , N_SSYM , type , offset );
c6ae69c6
PK
121 putprintf( " .stabs \"" , 1 );
122 putprintf( NAMEFORMAT , 1 , name );
b721c131 123 putprintf( "\",0x%x,0,0,0x%x" , 0 , N_LENG , length );
c6ae69c6
PK
124 }
125
126 /*
127 * left brackets
128 */
129stablbrac( level )
130 int level;
131 {
132
133 if ( ! opt('g') ) {
134 return;
135 }
b721c131 136 putprintf( " .stabd 0x%x,0,0x%x" , 0 , N_LBRAC , level );
c6ae69c6
PK
137 }
138
139 /*
140 * right brackets
141 */
142stabrbrac( level )
143 int level;
144 {
145
146 if ( ! opt('g') ) {
147 return;
148 }
b721c131 149 putprintf( " .stabd 0x%x,0,0x%x" , 0 , N_RBRAC , level );
c6ae69c6
PK
150 }
151
152 /*
153 * functions
154 */
b721c131 155stabfunc( name , class , line , level )
c6ae69c6 156 char *name;
b721c131 157 int class;
c6ae69c6
PK
158 int line;
159 long level;
160 {
b721c131
PK
161 int type;
162 long i;
078a6e08 163 char extname[ BUFSIZ ];
c6ae69c6 164
b721c131
PK
165 /*
166 * for separate compilation
167 */
168 if ( level == 1 ) {
169 if ( class == FUNC ) {
99f6998f
PK
170 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0
171 , name , N_PC , N_PGFUNC , ABS( line ) );
b721c131 172 } else if ( class == PROC ) {
99f6998f
PK
173 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0
174 , name , N_PC , N_PGPROC , ABS( line ) );
b721c131 175 }
c6ae69c6 176 }
b721c131
PK
177 /*
178 * for sdb
179 */
c6ae69c6
PK
180 if ( ! opt('g') ) {
181 return;
182 }
183 putprintf( " .stabs \"" , 1 );
184 putprintf( NAMEFORMAT , 1 , name );
078a6e08
PK
185 sextname( extname , name , level );
186 putprintf( "\",0x%x,0,0x%x,%s" , 0 , N_FUN , line , extname );
c6ae69c6
PK
187 }
188
189 /*
190 * source line numbers
191 */
192stabline( line )
193 int line;
194 {
195 if ( ! opt('g') ) {
196 return;
197 }
b721c131 198 putprintf( " .stabd 0x%x,0,0x%x" , 0 , N_SLINE , ABS( line ) );
c6ae69c6
PK
199 }
200
201 /*
202 * source files
203 */
204stabsource( filename )
205 char *filename;
206 {
b721c131 207 int label;
c6ae69c6 208
b721c131
PK
209 /*
210 * for separate compilation
211 */
99f6998f
PK
212 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0" , 0
213 , filename , N_PC , N_PSO );
b721c131
PK
214 /*
215 * for sdb
216 */
c6ae69c6
PK
217 if ( ! opt('g') ) {
218 return;
219 }
b721c131 220 label = getlab();
c6ae69c6
PK
221 putprintf( " .stabs \"" , 1 );
222 putprintf( NAMEFORMAT , 1 , filename );
b721c131 223 putprintf( "\",0x%x,0,0," , 1 , N_SO );
c6ae69c6
PK
224 putprintf( PREFIXFORMAT , 0 , LLABELPREFIX , label );
225 putprintf( PREFIXFORMAT , 1 , LLABELPREFIX , label );
226 putprintf( ":" , 0 );
227 }
228
229 /*
230 * included files get one or more of these:
231 * one as they are entered by a #include,
232 * and one every time they are returned to by nested #includes
233 */
234stabinclude( filename )
235 char *filename;
236 {
b721c131 237 int label;
c6ae69c6 238
99f6998f
PK
239 /*
240 * for separate compilation
241 */
242 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0" , 0
243 , filename , N_PC , N_PSOL );
b721c131
PK
244 /*
245 * for sdb
246 */
c6ae69c6
PK
247 if ( ! opt('g') ) {
248 return;
249 }
b721c131 250 label = getlab();
c6ae69c6
PK
251 putprintf( " .stabs \"" , 1 );
252 putprintf( NAMEFORMAT , 1 , filename );
b721c131 253 putprintf( "\",0x%x,0,0," , 1 , N_SOL );
c6ae69c6
PK
254 putprintf( PREFIXFORMAT , 0 , LLABELPREFIX , label );
255 putprintf( PREFIXFORMAT , 1 , LLABELPREFIX , label );
256 putprintf( ":" , 0 );
257 }
258
259
260/*
261 * global Pascal symbols :
262 * labels, types, constants, and external procedure and function names:
263 * These are used by the separate compilation facility
264 * to be able to check for disjoint header files.
c6ae69c6
PK
265 */
266
b721c131
PK
267 /*
268 * global labels
269 */
99f6998f 270stabglabel( label , line )
b721c131
PK
271 char *label;
272 int line;
c6ae69c6 273 {
c6ae69c6 274
99f6998f
PK
275 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0
276 , label , N_PC , N_PGLABEL , ABS( line ) );
c6ae69c6
PK
277 }
278
b721c131
PK
279 /*
280 * global constants
281 */
99f6998f
PK
282stabgconst( const , line )
283 char *const;
b721c131 284 int line;
c6ae69c6 285 {
c6ae69c6 286
99f6998f
PK
287 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0
288 , const , N_PC , N_PGCONST , ABS( line ) );
c6ae69c6
PK
289 }
290
b721c131
PK
291 /*
292 * global types
293 */
99f6998f
PK
294stabgtype( type , line )
295 char *type;
b721c131 296 int line;
c6ae69c6
PK
297 {
298
99f6998f
PK
299 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0
300 , type , N_PC , N_PGTYPE , ABS( line ) );
c6ae69c6
PK
301 }
302
303
b721c131
PK
304 /*
305 * external functions and procedures
306 */
307stabefunc( name , class , line )
308 char *name;
309 int class;
310 int line;
c6ae69c6 311 {
b721c131 312 int type;
c6ae69c6 313
b721c131 314 if ( class == FUNC ) {
99f6998f 315 type = N_PEFUNC;
b721c131 316 } else if ( class == PROC ) {
99f6998f 317 type = N_PEPROC;
b721c131
PK
318 } else {
319 return;
c6ae69c6 320 }
99f6998f
PK
321 putprintf( " .stabs \"%s\",0x%x,0,0x%x,0x%x" , 0
322 , name , N_PC , type , ABS( line ) );
c6ae69c6
PK
323 }
324
325#endif PC