furnace 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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 dominators
106
- unless @dominators
107
- # values of β will give rise to dom!
108
- dom = { @entry => Set[@entry] }
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 == @entry
112
- dom[node] = @nodes.dup
113
- end
118
+ next if node == start
114
119
 
115
- change = true
116
- while change
117
- change = false
118
- @nodes.each do |node|
119
- next if node == @entry
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
- @dominators = dom
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
- @dominators
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
@@ -1,3 +1,3 @@
1
1
  module Furnace
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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.1
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-11 00:00:00.000000000 Z
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.