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