furnace 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/furnace/cfg/graph.rb +44 -32
- data/lib/furnace/version.rb +1 -1
- metadata +2 -2
data/lib/furnace/cfg/graph.rb
CHANGED
@@ -102,45 +102,56 @@ module Furnace::CFG
|
|
102
102
|
|
103
103
|
# Shamelessly stolen from
|
104
104
|
# http://www.cs.colostate.edu/~mstrout/CS553/slides/lecture04.pdf
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
def compute_generic_domination(start, forward)
|
106
|
+
# values of β will give rise to dom!
|
107
|
+
dom = { start => Set[start] }
|
108
|
+
|
109
|
+
@nodes.each do |node|
|
110
|
+
next if node == start
|
111
|
+
dom[node] = @nodes.dup
|
112
|
+
end
|
109
113
|
|
114
|
+
change = true
|
115
|
+
while change
|
116
|
+
change = false
|
110
117
|
@nodes.each do |node|
|
111
|
-
next if node ==
|
112
|
-
dom[node] = @nodes.dup
|
113
|
-
end
|
118
|
+
next if node == start
|
114
119
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
# Key Idea
|
122
|
-
# If a node dominates all
|
123
|
-
# predecessors of node n, then it
|
124
|
-
# also dominates node n.
|
125
|
-
pred = node.sources.map do |source|
|
126
|
-
dom[source]
|
127
|
-
end.reduce(:&)
|
128
|
-
|
129
|
-
# An exception handler header node has no regular sources.
|
130
|
-
pred = [] if pred.nil?
|
131
|
-
|
132
|
-
current = Set[node].merge(pred)
|
133
|
-
if current != dom[node]
|
134
|
-
dom[node] = current
|
135
|
-
change = true
|
136
|
-
end
|
120
|
+
# Are we computing dominators or postdominators?
|
121
|
+
if forward
|
122
|
+
edges = node.sources
|
123
|
+
else
|
124
|
+
edges = node.targets
|
137
125
|
end
|
138
|
-
end
|
139
126
|
|
140
|
-
|
127
|
+
# Key Idea [for dominators]
|
128
|
+
# If a node dominates all
|
129
|
+
# predecessors of node n, then it
|
130
|
+
# also dominates node n.
|
131
|
+
pred = edges.map do |source|
|
132
|
+
dom[source]
|
133
|
+
end.reduce(:&)
|
134
|
+
|
135
|
+
# An exception handler header node has no regular sources.
|
136
|
+
pred = [] if pred.nil?
|
137
|
+
|
138
|
+
current = Set[node].merge(pred)
|
139
|
+
if current != dom[node]
|
140
|
+
dom[node] = current
|
141
|
+
change = true
|
142
|
+
end
|
143
|
+
end
|
141
144
|
end
|
142
145
|
|
143
|
-
|
146
|
+
dom
|
147
|
+
end
|
148
|
+
|
149
|
+
def dominators
|
150
|
+
@dominators ||= compute_generic_domination(@entry, true)
|
151
|
+
end
|
152
|
+
|
153
|
+
def postdominators
|
154
|
+
@postdominators ||= compute_generic_domination(@exit, false)
|
144
155
|
end
|
145
156
|
|
146
157
|
# See also {#dominators} for references.
|
@@ -148,6 +159,7 @@ module Furnace::CFG
|
|
148
159
|
loops = Hash.new { |h,k| h[k] = Set.new }
|
149
160
|
|
150
161
|
dom = dominators
|
162
|
+
|
151
163
|
@nodes.each do |node|
|
152
164
|
node.targets.each do |target|
|
153
165
|
# Back edges
|
data/lib/furnace/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: furnace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-16 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Furnace is a static code analysis framework for dynamic languages, aimed
|
15
15
|
at efficient type and behavior inference.
|