lib/damsi/dfg.rb in damsi-0.0.1 vs lib/damsi/dfg.rb in damsi-0.0.2

- old
+ new

@@ -17,12 +17,13 @@ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. require_relative 'ticks' +require_relative 'advisor' -# Dataflow Graph (DFG) +# Dataflow Graph (DFG). # Author:: Yegor Bugayenko (yegor256@gmail.com) # Copyright:: Copyright (c) 2023 Yegor Bugayenko # License:: MIT class Damsi::DFG def initialize(prog, log) @@ -32,25 +33,65 @@ @ops = {} @ticks = Damsi::Ticks.new @tick = 0 @op = nil @started = [] + @advisor = Damsi::Advisor.new(self, @ticks, log) + @links = [] + @edges = [] end + # Add edge (only for information). + def edge(arc, left, right) + @edges.push({ arc: arc, v1: left, v2: right }) + end + + # The edge exists? + def e?(arc, left, right) + @edges.each do |e| + next if !arc.nil? && e[:arc] != arc + next if !left.nil? && e[:v1] != left + next if !right.nil? && e[:v2] != right + return e[:arc] if arc.nil? + return e[:v1] if left.nil? + return e[:v2] if right.nil? + return true + end + false + end + + # Add link to external entity, like RAM. + def link(vtx, ext) + @links.push({ vtx: vtx, ext: ext }) + end + + # The semantic of the vertex is memory related? + def m?(vtx, ext) + @links.each do |l| + next if !vtx.nil? && l[:vtx] != vtx + next if !ext.nil? && l[:ext] != ext + return l[:vtx] if vtx.nil? + return l[:ext] if ext.nil? + return true + end + false + end + def cell(vtx) @cells[vtx] end def msg(tex) @ticks.push(@tick, "\\texttt{\\frenchspacing{}#{@op}: #{tex}}") end - def send(vtx, args) - @cells[vtx] = {} if @cells[vtx].nil? - args.each do |k, a| - @cells[vtx][k] = a - @ticks.push(@tick, "\\texttt{\\frenchspacing{}#{@op}: \"#{a}\" → #{vtx}.#{k}}") - @log.debug("#{@tick}| #{a} -> #{vtx}.#{k}") + # Send "data" through the "arc" to the vertex "vtx" + def send(vtx, arc, data) + @advisor.redirect({ tick: @tick, v1: @op, v2: vtx, arc: arc, data: data }).each do |ic| + @cells[ic[:v2]] = {} if @cells[ic[:v2]].nil? + @cells[ic[:v2]][ic[:arc]] = ic[:data] + @ticks.push(@tick, "\\texttt{\\frenchspacing{}#{@op}: \"#{ic[:data]}\" → #{ic[:v2]}.#{ic[:arc]}}") + @log.debug("#{@tick}| #{ic[:data]} -> #{ic[:v2]}.#{ic[:arc]}") end end def recv(vtx, &block) @ops[vtx] = block