dfn.c (7c478bd9) | dfn.c (92ed1782) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 5 unchanged lines hidden (view full) --- 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * --- 5 unchanged lines hidden (view full) --- 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ |
22 |
|
22/* | 23/* |
23 * Copyright (c) 1990-1997,2001 by Sun Microsystems, Inc. 24 * All rights reserved. | 24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. |
25 */ 26 27#pragma ident "%Z%%M% %I% %E% SMI" 28 29#include <stdio.h> 30#include "gprof.h" 31 32#define DFN_DEPTH 100 --- 16 unchanged lines hidden (view full) --- 49 */ 50void 51dfn(nltype *parentp) 52{ 53 arctype *arcp; 54 55#ifdef DEBUG 56 if (debug & DFNDEBUG) { | 26 */ 27 28#pragma ident "%Z%%M% %I% %E% SMI" 29 30#include <stdio.h> 31#include "gprof.h" 32 33#define DFN_DEPTH 100 --- 16 unchanged lines hidden (view full) --- 50 */ 51void 52dfn(nltype *parentp) 53{ 54 arctype *arcp; 55 56#ifdef DEBUG 57 if (debug & DFNDEBUG) { |
57 printf("[dfn] dfn("); | 58 (void) printf("[dfn] dfn("); |
58 printname(parentp); | 59 printname(parentp); |
59 printf(")\n"); | 60 (void) printf(")\n"); |
60 } 61#endif /* DEBUG */ 62 63 if (!dfn_stack) { 64 dfn_sz = DFN_DEPTH; 65 dfn_stack = (dfntype *) malloc(dfn_sz * sizeof (dfntype)); 66 if (!dfn_stack) { | 61 } 62#endif /* DEBUG */ 63 64 if (!dfn_stack) { 65 dfn_sz = DFN_DEPTH; 66 dfn_stack = (dfntype *) malloc(dfn_sz * sizeof (dfntype)); 67 if (!dfn_stack) { |
67 fprintf(stderr, | 68 (void) fprintf(stderr, |
68 "fatal: can't malloc %d objects\n", dfn_sz); 69 exit(1); 70 } 71 } 72 73 /* 74 * if we're already numbered, no need to look any furthur. 75 */ --- 31 unchanged lines hidden (view full) --- 107void 108dfn_pre_visit(nltype *parentp) 109{ 110 111 if (!dfn_stack) { 112 dfn_sz = DFN_DEPTH; 113 dfn_stack = (dfntype *) malloc(dfn_sz * sizeof (dfntype)); 114 if (!dfn_stack) { | 69 "fatal: can't malloc %d objects\n", dfn_sz); 70 exit(1); 71 } 72 } 73 74 /* 75 * if we're already numbered, no need to look any furthur. 76 */ --- 31 unchanged lines hidden (view full) --- 108void 109dfn_pre_visit(nltype *parentp) 110{ 111 112 if (!dfn_stack) { 113 dfn_sz = DFN_DEPTH; 114 dfn_stack = (dfntype *) malloc(dfn_sz * sizeof (dfntype)); 115 if (!dfn_stack) { |
115 printf("fatal: can't malloc %d objects\n", dfn_sz); | 116 (void) printf("fatal: can't malloc %d objects\n", 117 dfn_sz); |
116 exit(1); 117 } 118 } 119 120 dfn_depth += 1; 121 122 if (dfn_depth >= dfn_sz) { 123 dfn_sz += DFN_DEPTH; 124 dfn_stack = (dfntype *) realloc(dfn_stack, 125 dfn_sz * sizeof (dfntype)); 126 127 if (!dfn_stack) { | 118 exit(1); 119 } 120 } 121 122 dfn_depth += 1; 123 124 if (dfn_depth >= dfn_sz) { 125 dfn_sz += DFN_DEPTH; 126 dfn_stack = (dfntype *) realloc(dfn_stack, 127 dfn_sz * sizeof (dfntype)); 128 129 if (!dfn_stack) { |
128 fprintf(stderr, | 130 (void) fprintf(stderr, |
129 "fatal: can't realloc %d objects\n", dfn_sz); 130 exit(1); 131 } 132 } 133 134 dfn_stack[dfn_depth].nlentryp = parentp; 135 dfn_stack[dfn_depth].cycletop = dfn_depth; 136 parentp->toporder = DFN_BUSY; 137 138#ifdef DEBUG 139 if (debug & DFNDEBUG) { | 131 "fatal: can't realloc %d objects\n", dfn_sz); 132 exit(1); 133 } 134 } 135 136 dfn_stack[dfn_depth].nlentryp = parentp; 137 dfn_stack[dfn_depth].cycletop = dfn_depth; 138 parentp->toporder = DFN_BUSY; 139 140#ifdef DEBUG 141 if (debug & DFNDEBUG) { |
140 printf("[dfn_pre_visit]\t\t%d:", dfn_depth); | 142 (void) printf("[dfn_pre_visit]\t\t%d:", dfn_depth); |
141 printname(parentp); | 143 printname(parentp); |
142 printf("\n"); | 144 (void) printf("\n"); |
143 } 144#endif /* DEBUG */ 145} 146 147/* 148 * are we already numbered? 149 */ 150bool --- 32 unchanged lines hidden (view full) --- 183 break; 184 } 185 186 if (cycletop <= 0) { 187 /* 188 * don't report non existent functions 189 */ 190 if (childp->value) { | 145 } 146#endif /* DEBUG */ 147} 148 149/* 150 * are we already numbered? 151 */ 152bool --- 32 unchanged lines hidden (view full) --- 185 break; 186 } 187 188 if (cycletop <= 0) { 189 /* 190 * don't report non existent functions 191 */ 192 if (childp->value) { |
191 fprintf(stderr, "[dfn_findcycle] couldn't find head " | 193 (void) fprintf(stderr, 194 "[dfn_findcycle] couldn't find head " |
192 "of cycle for %s\n", childp->name); 193 return; 194 } 195 } 196 197#ifdef DEBUG 198 if (debug & DFNDEBUG) { | 195 "of cycle for %s\n", childp->name); 196 return; 197 } 198 } 199 200#ifdef DEBUG 201 if (debug & DFNDEBUG) { |
199 printf("[dfn_findcycle] dfn_depth %d cycletop %d ", | 202 (void) printf("[dfn_findcycle] dfn_depth %d cycletop %d ", |
200 dfn_depth, cycletop); 201 printname(cycleheadp); | 203 dfn_depth, cycletop); 204 printname(cycleheadp); |
202 printf("\n"); | 205 (void) printf("\n"); |
203 } 204#endif /* DEBUG */ 205 206 if (cycletop == dfn_depth) { 207 /* 208 * this is previous function, e.g. this calls itself 209 * sort of boring 210 */ --- 4 unchanged lines hidden (view full) --- 215 * glommed into this cycle. 216 * things have been glommed when their cyclehead field 217 * points to the head of the cycle they are glommed into. 218 */ 219 for (tailp = cycleheadp; tailp->cnext; tailp = tailp->cnext) { 220 /* void: chase down to tail of things already glommed */ 221#ifdef DEBUG 222 if (debug & DFNDEBUG) { | 206 } 207#endif /* DEBUG */ 208 209 if (cycletop == dfn_depth) { 210 /* 211 * this is previous function, e.g. this calls itself 212 * sort of boring 213 */ --- 4 unchanged lines hidden (view full) --- 218 * glommed into this cycle. 219 * things have been glommed when their cyclehead field 220 * points to the head of the cycle they are glommed into. 221 */ 222 for (tailp = cycleheadp; tailp->cnext; tailp = tailp->cnext) { 223 /* void: chase down to tail of things already glommed */ 224#ifdef DEBUG 225 if (debug & DFNDEBUG) { |
223 printf("[dfn_findcycle] tail "); | 226 (void) printf("[dfn_findcycle] tail "); |
224 printname(tailp); | 227 printname(tailp); |
225 printf("\n"); | 228 (void) printf("\n"); |
226 } 227#endif /* DEBUG */ 228 } 229 230 /* 231 * if what we think is the top of the cycle 232 * has a cyclehead field, then it's not really the 233 * head of the cycle, which is really what we want 234 */ 235 if (cycleheadp->cyclehead != cycleheadp) { 236 cycleheadp = cycleheadp->cyclehead; 237#ifdef DEBUG 238 if (debug & DFNDEBUG) { | 229 } 230#endif /* DEBUG */ 231 } 232 233 /* 234 * if what we think is the top of the cycle 235 * has a cyclehead field, then it's not really the 236 * head of the cycle, which is really what we want 237 */ 238 if (cycleheadp->cyclehead != cycleheadp) { 239 cycleheadp = cycleheadp->cyclehead; 240#ifdef DEBUG 241 if (debug & DFNDEBUG) { |
239 printf("[dfn_findcycle] new cyclehead "); | 242 (void) printf("[dfn_findcycle] new cyclehead "); |
240 printname(cycleheadp); | 243 printname(cycleheadp); |
241 printf("\n"); | 244 (void) printf("\n"); |
242 } 243#endif /* DEBUG */ 244 } 245 246 for (index = cycletop + 1; index <= dfn_depth; index += 1) { 247 248 childp = dfn_stack[index].nlentryp; 249 if (childp->cyclehead == childp) { 250 /* 251 * not yet glommed anywhere, glom it 252 * and fix any children it has glommed 253 */ 254 tailp->cnext = childp; 255 childp->cyclehead = cycleheadp; 256#ifdef DEBUG 257 if (debug & DFNDEBUG) { | 245 } 246#endif /* DEBUG */ 247 } 248 249 for (index = cycletop + 1; index <= dfn_depth; index += 1) { 250 251 childp = dfn_stack[index].nlentryp; 252 if (childp->cyclehead == childp) { 253 /* 254 * not yet glommed anywhere, glom it 255 * and fix any children it has glommed 256 */ 257 tailp->cnext = childp; 258 childp->cyclehead = cycleheadp; 259#ifdef DEBUG 260 if (debug & DFNDEBUG) { |
258 printf("[dfn_findcycle] glomming "); | 261 (void) printf( 262 "[dfn_findcycle] glomming "); |
259 printname(childp); | 263 printname(childp); |
260 printf(" onto "); | 264 (void) printf(" onto "); |
261 printname(cycleheadp); | 265 printname(cycleheadp); |
262 printf("\n"); | 266 (void) printf("\n"); |
263 } 264#endif /* DEBUG */ 265 for (tailp = childp; tailp->cnext; 266 tailp = tailp->cnext) { 267 tailp->cnext->cyclehead = cycleheadp; 268#ifdef DEBUG 269 if (debug & DFNDEBUG) { | 267 } 268#endif /* DEBUG */ 269 for (tailp = childp; tailp->cnext; 270 tailp = tailp->cnext) { 271 tailp->cnext->cyclehead = cycleheadp; 272#ifdef DEBUG 273 if (debug & DFNDEBUG) { |
270 printf("[dfn_findcycle]" | 274 (void) printf("[dfn_findcycle]" |
271 " and its tail "); 272 printname(tailp->cnext); | 275 " and its tail "); 276 printname(tailp->cnext); |
273 printf(" onto "); | 277 (void) printf(" onto "); |
274 printname(cycleheadp); | 278 printname(cycleheadp); |
275 printf("\n"); | 279 (void) printf("\n"); |
276 } 277#endif /* DEBUG */ 278 } 279 } else if (childp->cyclehead != cycleheadp) { | 280 } 281#endif /* DEBUG */ 282 } 283 } else if (childp->cyclehead != cycleheadp) { |
280 fprintf(stderr, "[dfn_busy] glommed," | 284 (void) fprintf(stderr, "[dfn_busy] glommed," |
281 " but not to cyclehead\n"); 282 } 283 } 284 } 285} 286 287/* 288 * deal with self-cycles --- 4 unchanged lines hidden (view full) --- 293dfn_self_cycle(nltype *parentp) 294{ 295 /* 296 * since we are taking out self-cycles elsewhere 297 * no need for the special case, here. 298 */ 299#ifdef DEBUG 300 if (debug & DFNDEBUG) { | 285 " but not to cyclehead\n"); 286 } 287 } 288 } 289} 290 291/* 292 * deal with self-cycles --- 4 unchanged lines hidden (view full) --- 297dfn_self_cycle(nltype *parentp) 298{ 299 /* 300 * since we are taking out self-cycles elsewhere 301 * no need for the special case, here. 302 */ 303#ifdef DEBUG 304 if (debug & DFNDEBUG) { |
301 printf("[dfn_self_cycle] "); | 305 (void) printf("[dfn_self_cycle] "); |
302 printname(parentp); | 306 printname(parentp); |
303 printf("\n"); | 307 (void) printf("\n"); |
304 } 305#endif /* DEBUG */ 306} 307 308/* 309 * visit a node after all its children 310 * [MISSING: an explanation] 311 * and pop it off the stack 312 */ 313void 314dfn_post_visit(nltype *parentp) 315{ 316 nltype *memberp; 317 318#ifdef DEBUG 319 if (debug & DFNDEBUG) { | 308 } 309#endif /* DEBUG */ 310} 311 312/* 313 * visit a node after all its children 314 * [MISSING: an explanation] 315 * and pop it off the stack 316 */ 317void 318dfn_post_visit(nltype *parentp) 319{ 320 nltype *memberp; 321 322#ifdef DEBUG 323 if (debug & DFNDEBUG) { |
320 printf("[dfn_post_visit]\t%d: ", dfn_depth); | 324 (void) printf("[dfn_post_visit]\t%d: ", dfn_depth); |
321 printname(parentp); | 325 printname(parentp); |
322 printf("\n"); | 326 (void) printf("\n"); |
323 } 324#endif /* DEBUG */ 325 /* 326 * number functions and things in their cycles 327 * unless the function is itself part of a cycle 328 */ 329 if (parentp->cyclehead == parentp) { 330 dfn_counter += 1; 331 332 for (memberp = parentp; memberp; memberp = memberp->cnext) { 333 334 memberp->toporder = dfn_counter; 335#ifdef DEBUG 336 if (debug & DFNDEBUG) { | 327 } 328#endif /* DEBUG */ 329 /* 330 * number functions and things in their cycles 331 * unless the function is itself part of a cycle 332 */ 333 if (parentp->cyclehead == parentp) { 334 dfn_counter += 1; 335 336 for (memberp = parentp; memberp; memberp = memberp->cnext) { 337 338 memberp->toporder = dfn_counter; 339#ifdef DEBUG 340 if (debug & DFNDEBUG) { |
337 printf("[dfn_post_visit]\t\tmember "); | 341 (void) printf("[dfn_post_visit]\t\tmember "); |
338 printname(memberp); | 342 printname(memberp); |
339 printf(" -> toporder = %d\n", dfn_counter); | 343 (void) printf(" -> toporder = %d\n", 344 dfn_counter); |
340 } 341#endif /* DEBUG */ 342 } 343#ifdef DEBUG 344 } else { 345 if (debug & DFNDEBUG) | 345 } 346#endif /* DEBUG */ 347 } 348#ifdef DEBUG 349 } else { 350 if (debug & DFNDEBUG) |
346 printf("[dfn_post_visit]\t\tis part of a cycle\n"); | 351 (void) printf( 352 "[dfn_post_visit]\t\tis part of a cycle\n"); |
347#endif /* DEBUG */ 348 } 349 dfn_depth -= 1; 350} | 353#endif /* DEBUG */ 354 } 355 dfn_depth -= 1; 356} |