Skip to content

Commit

Permalink
Adding dependency and cycle support to depanalysis and to its clients…
Browse files Browse the repository at this point in the history
… in bud_meta and tc_meta

	modified:   ../lib/bud/bud_meta.rb
	modified:   ../lib/bud/depanalysis.rb
	modified:   ../lib/bud/viz_util.rb
	modified:   tc_meta.rb
  • Loading branch information
sriram-srinivasan committed Mar 12, 2012
1 parent cfb19b5 commit 6a8dc4e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/bud/bud_meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ def depanalysis
require 'bud/depanalysis'
da = ::DepAnalysis.new
da.providing <+ @bud_instance.tables[:t_provides].to_a
da.depends_tc <+ @bud_instance.tables[:t_depends].map{|t| [t.lhs, t.body]}
da.depends <+ @bud_instance.t_depends.map{|d| [d.lhs, d.op, d.body, d.nm]}

#@bud_instance.tables[:t_provides].each {|t| da.providing <+ t}
#@bud_instance.tables[:t_depends].each {|t| da.depends_tc <+ t}
3.times { da.tick_internal}
da.tick_internal
@dependency_analysis = da
end
@dependency_analysis
Expand Down
39 changes: 32 additions & 7 deletions lib/bud/depanalysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,43 @@ class DepAnalysis #:nodoc: all
include Bud

state do
# Data inserted by client, usually from t_depends and t_provides
scratch :depends, [:lhs, :op, :body, :neg]
scratch :providing, [:pred, :input]

table :depends_tc, [:lhs, :body]
# Intermediate state
scratch :depends_clean, [:lhs, :body, :neg, :temporal]

table :providing, [:pred, :input]
table :underspecified, [:pred, :input]


table :source, [:pred]
table :sink, [:pred]
scratch :depends_tc, [:lhs, :body, :via, :neg, :temporal]
scratch :cycle, [:pred, :via, :neg, :temporal]
scratch :underspecified, [:pred, :input]
scratch :source, [:pred]
scratch :sink, [:pred]
end

bloom :analysis do
depends_clean <= depends do |d|
is_temporal = (d.op.to_s =~ /<[\+\-\~]/)
[d.lhs, d.body, d.neg, is_temporal]
end

# Compute the transitive closure of "depends_clean" to detect cycles in
# the deductive fragment of the program.
depends_tc <= depends_clean do |d|
[d.lhs, d.body, d.body, d.neg, d.temporal]
end
depends_tc <= (depends_clean * depends_tc).pairs(:body => :lhs) do |b, r|
[b.lhs, r.body, b.body, (b.neg or r.neg), (b.temporal or r.temporal)]
end

cycle <= depends_tc do |d|
if d.lhs == d.body
unless d.neg and !d.temporal
[d.lhs, d.via, d.neg, d.temporal]
end
end
end

source <= providing do |p|
if p.input and !depends_tc.map{|d| d.lhs}.include? p.pred
[p.pred]
Expand Down
5 changes: 3 additions & 2 deletions lib/bud/viz_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ def graph_from_instance(bud_instance, viz_name, output_base, collapse=true, fmt=
bit = bud_instance.builtin_tables
VizUtil.ma_tables.each_pair{|k, v| bit[k] = v}

write_graphs(tabinf, bit, bud_instance.t_cycle,
depanalysis = bud_instance.meta_parser.depanalysis
write_graphs(tabinf, bit, depanalysis.cycle,
bud_instance.t_depends, bud_instance.t_rules, viz_name,
output_base, fmt, collapse, bud_instance.meta_parser.depanalysis, -1, nil,
output_base, fmt, collapse, depanalysis, -1, nil,
get_labels(bud_instance), begins)
begins
end
Expand Down
10 changes: 4 additions & 6 deletions test/tc_meta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ def str2struct(content)
end

def test_plotting
puts "tc_meta::test_plotting disabled temporarily"
return

$stdout = StringIO.new("", "w")
program = KTest2.new(:output => :dot)
dep = DepAnalysis.new

Expand All @@ -234,8 +232,7 @@ def test_plotting
program.sync_do

dep.providing <+ program.t_provides.to_a
dep.depends_tc <+ program.t_depends.map{|d| [d.lhs, d.body]}
dep.sync_do
dep.depends <+ program.t_depends.map{|d| [d.lhs, d.op, d.body, d.nm]}
dep.sync_do

dir = scratch_dir
Expand All @@ -244,14 +241,15 @@ def test_plotting

looks = str2struct(content)

assert_match(/upd -> \"interm, mystate\" \[label=\" \+\/\-\",.+?arrowhead=veeodot/, content)
assert_match(/upd -> \"interm, mystate\" \[.*label=\" \+\/\-\"/, content)
assert_match("S -> upd", content)
assert_match("S -> req", content)
assert_match("sinkhole -> \"\?\?\"", content)
assert_no_match(/upd -> \"\?\?\"/, content)
assert_no_match(/req -> \"\?\?\"/, content)
`rm -r #{dir}`
program.stop
$stdout = STDOUT
end

def test_labels
Expand Down

0 comments on commit 6a8dc4e

Please sign in to comment.