Permalink
Browse files

labeling

  • Loading branch information...
palvaro committed Sep 28, 2012
1 parent e92f8e9 commit d7f0683445989e7b445ebca8c1e976bbf10c2ac8
Showing with 743 additions and 1 deletion.
  1. +41 −0 bin/budlabel
  2. +1 −1 bud.gemspec
  3. +49 −0 lib/bud/labeling/bloomgraph.rb
  4. +64 −0 lib/bud/labeling/budplot_style.rb
  5. +297 −0 lib/bud/labeling/labeling.rb
  6. +291 −0 test/tc_labeling.rb
View
@@ -0,0 +1,41 @@
+require 'rubygems'
+require 'bud'
+require 'getopt/std'
+require 'bud/labeling/labeling'
+require 'bud/labeling/bloomgraph'
+require 'bud/labeling/budplot_style'
+
+$LOAD_PATH.unshift(".")
+
+@opts = Getopt::Std.getopts("r:i:p:CPA")
+
+unless @opts["r"] and @opts["i"]
+ puts "USAGE:"
+ puts "-r REQUIRE"
+ puts "-i INCLUDE"
+ puts "[-p INCLUDE PATH]"
+ puts "-C Concise output -- Associate a single label with each output interface"
+ puts "-P Path-based output -- For each output interface, attribute a label to paths from each input interface"
+ exit
+end
+
+if @opts["p"]
+ $LOAD_PATH.unshift @opts["p"]
+end
+
+require @opts["r"]
+c = Label.new(@opts["i"])
+
+if @opts["C"]
+ c.concise.each_pair do |k, v|
+ puts "#{k} = #{v}"
+ end
+end
+
+if @opts["P"]
+ c.paths.each do |z|
+ puts "#{z}"
+ end
+end
+
+c.write_graph
View
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.rubyforge_project = 'bloom-lang'
s.files = Dir['lib/**/*'] + Dir['bin/*'] + Dir['docs/**/*'] + Dir['examples/**/*'] + %w[README.md LICENSE History.txt]
- s.executables = %w[rebl budplot budvis budtimelines]
+ s.executables = %w[rebl budplot budvis budtimelines budlabel]
s.default_executable = 'rebl'
s.add_dependency 'eventmachine'
@@ -0,0 +1,49 @@
+require 'rubygems'
+require 'bud'
+require 'graphviz'
+
+# the idea is, a simple interface between graphviz and bud.
+
+module BudGraph
+ state do
+ interface input, :bnode, [:name] => [:meta]
+ interface input, :bedge, [:from, :to, :meta]
+ end
+end
+
+module BloomGraph
+ include BudGraph
+
+ state do
+ table :nodes, bnode.schema
+ table :edges, bedge.schema
+ end
+
+ bloom do
+ nodes <= bnode
+ edges <= bedge
+ end
+
+ def finish(ignore, name, fmt=:pdf)
+ it = {}
+ ignore.each{|i| it[i] = true}
+ tick
+ nodes.to_a.each do |n|
+ unless it[n.name.to_sym]
+ @graph.add_nodes(n.name, n.meta)
+ end
+ end
+
+ edges.to_a.each do |e|
+ unless it[e.from.to_sym] or it[e.to.to_sym]
+ @graph.add_edges(e.from, e.to, e.meta)
+ end
+ end
+ @graph.output(fmt => name)
+ end
+
+ def initialize(opts={:type => :digraph})
+ @graph = GraphViz.new(:G, opts)
+ super
+ end
+end
@@ -0,0 +1,64 @@
+#require 'bloomgraph'
+
+module PDG
+ # a bloomgraph program that plots a NM-and-async-aware PDG
+ state do
+ scratch :bodies, [:table] => [:type]
+ scratch :source, [:pred]
+ scratch :sink, [:pred]
+ end
+
+ bloom do
+ bodies <= dep{|d| [d.body, coll_type(d.body)]}
+ bodies <= dep{|d| [d.head, coll_type(d.head)]}
+
+ bnode <= bodies do |b|
+ shape = case b.type
+ when Bud::BudTable then "rectangle"
+ when Bud::LatticeWrapper then "triangle"
+ else "oval"
+ end
+ [b.table, {:shape => shape}]
+ end
+
+ bedge <= dep do |d|
+ line = d.label == "A" ? "dashed" : "solid"
+ circle = d.label == "N" ? "veeodot" : "normal"
+ [d.body, d.head, {:style => line, :arrowhead => circle, :penwidth => 5}]
+ end
+ end
+
+ bloom :endpointss do
+ source <= t_provides do |p|
+ if p.input and !dep_tc.map{|d| d.head}.include? p.interface
+ [p.interface]
+ end
+ end
+
+ sink <= t_provides do |p|
+ if !p.input and !dep_tc.map{|d| d.body}.include? p.interface
+ [p.interface]
+ end
+ end
+
+ bedge <= source{|s| ["S", s.pred, {}]}
+ bedge <= sink{|s| [s.pred, "T", {}]}
+ end
+
+ bootstrap do
+ bnode << ["S", {:shape => "diamond", :color => "blue"}]
+ bnode << ["T", {:shape => "diamond", :color => "blue"}]
+ end
+
+ def coll_type(cn)
+ tab = self.tables[cn.to_sym]
+ if tab.nil?
+ tab = self.lattices[cn.to_sym]
+ if tab.nil?
+ return nil
+ end
+ end
+ tab.class
+ end
+end
+
Oops, something went wrong.

0 comments on commit d7f0683

Please sign in to comment.