home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
mitsch75.zip
/
scheme-7_5_17-src.zip
/
scheme-7.5.17
/
src
/
compiler
/
fgopt
/
conect.scm
< prev
next >
Wrap
Text File
|
1999-01-02
|
3KB
|
85 lines
#| -*-Scheme-*-
$Id: conect.scm,v 4.5 1999/01/02 06:06:43 cph Exp $
Copyright (c) 1987, 1988, 1999 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|#
;;;; FG Connectivity Analysis
(declare (usual-integrations))
(define (connectivity-analysis expression procedures)
(walk-node (expression-entry-node expression) (make-subgraph-color))
(for-each (lambda (procedure)
(if (not (procedure-direct-linked? procedure))
(walk-node (procedure-entry-node procedure)
(make-subgraph-color))))
procedures))
(define (procedure-direct-linked? procedure)
(if (procedure-continuation? procedure)
(and (continuation/ever-known-operator? procedure)
(there-exists? (continuation/combinations procedure)
(lambda (combination)
(and (combination/inline? combination)
(combination/continuation-push combination)))))
(procedure-inline-code? procedure)))
(define (walk-node node color)
(let ((color* (node/subgraph-color node)))
(cond ((not color*)
(color-node! node color)
(walk-next node color))
((not (eq? color color*))
(recolor-nodes! (subgraph-color/nodes color*) color)))))
(define (color-node! node color)
(set-node/subgraph-color! node color)
(set-subgraph-color/nodes! color (cons node (subgraph-color/nodes color))))
(define (recolor-nodes! nodes color)
(for-each (lambda (node)
(set-node/subgraph-color! node color))
nodes)
(set-subgraph-color/nodes! color
(append! nodes (subgraph-color/nodes color))))
(define (walk-next node color)
(cfg-node-case (tagged-vector/tag node)
((APPLICATION)
(case (application-type node)
((COMBINATION)
(if (combination/inline? node)
(walk-continuation (combination/continuation node) color)
(let ((operator (rvalue-known-value (application-operator node))))
(if (and operator
(rvalue/procedure? operator)
(procedure-inline-code? operator))
(walk-node (procedure-entry-node operator) color)))))
((RETURN)
(walk-continuation (return/operator node) color))))
((VIRTUAL-RETURN POP ASSIGNMENT DEFINITION FG-NOOP STACK-OVERWRITE)
(walk-node (snode-next node) color))
((TRUE-TEST)
(walk-node (pnode-consequent node) color)
(walk-node (pnode-alternative node) color))))
(define (walk-continuation continuation color)
(let ((rvalue (rvalue-known-value continuation)))
(if rvalue
(walk-node (continuation/entry-node rvalue) color))))