Class: Gisele::Analysis::Compiling::Ast2Graph

Inherits:
Sexpr::Rewriter
  • Object
show all
Defined in:
lib/gisele/analysis/compiling/ast2graph.rb

Defined Under Namespace

Modules: Connector

Instance Method Summary collapse

Instance Method Details

#on_case_st(sexpr) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gisele/analysis/compiling/ast2graph.rb', line 81

def on_case_st(sexpr)
  cond, *clauses = sexpr.sexpr_body

  entry, exit = entry_and_exit(sexpr)

  diamond = add_vertex(sexpr)
  connect(entry, diamond)

  clauses.each do |clause|
    c_entry, c_exit = apply(clause.last)
    connect(diamond, c_entry, clause)
    connect(c_exit, exit)
  end

  [entry, exit]
end

#on_if_st(sexpr) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/gisele/analysis/compiling/ast2graph.rb', line 58

def on_if_st(sexpr)
  cond, then_clause, else_clause, = sexpr.sexpr_body

  entry, exit = entry_and_exit(sexpr)

  diamond = add_vertex(sexpr)
  connect(entry, diamond)

  c_entry, c_exit = apply(then_clause)
  connect(diamond, c_entry, true_ast_sexpr)
  connect(c_exit, exit)

  if else_clause
    c_entry, c_exit = apply(else_clause.last)
    connect(diamond, c_entry, false_ast_sexpr)
    connect(c_exit, exit)
  else
    connect(diamond, exit, false_ast_sexpr)
  end

  [entry, exit]
end

#on_par_st(sexpr) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/gisele/analysis/compiling/ast2graph.rb', line 48

def on_par_st(sexpr)
  entry, exit = add_vertex(sexpr), add_vertex(sexpr)
  sexpr.sexpr_body.each do |child|
    c_entry, c_exit = apply(child)
    connect(entry, c_entry)
    connect(c_exit, exit)
  end
  [entry, exit]
end

#on_seq_st(sexpr) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gisele/analysis/compiling/ast2graph.rb', line 36

def on_seq_st(sexpr)
  mine    = entry_and_exit(sexpr)
  current = mine.first
  sexpr.sexpr_body.each do |child|
    c_entry, c_exit = apply(child)
    connect(current, c_entry)
    current = c_exit
  end
  connect(current, mine.last)
  mine
end

#on_task_call_st(sexpr) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/gisele/analysis/compiling/ast2graph.rb', line 116

def on_task_call_st(sexpr)
  entry, exit = entry_and_exit(sexpr)
  task = add_vertex(sexpr)
  connect(entry, task)
  connect(task, exit)
  [entry, exit]
end

#on_task_def(sexpr) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gisele/analysis/compiling/ast2graph.rb', line 18

def on_task_def(sexpr)
  @graph = Yargi::Digraph.new

  entry, exit = add_vertex(sexpr), add_vertex(sexpr)
  c_entry, c_exit = apply(sexpr.last)
  connect(entry, c_entry)
  connect(c_exit, exit)

  @graph.vertices(Connector).each do |vertex|
    next unless vertex.out_edges.size == 1
    target = vertex.out_edges.first.target
    @graph.reconnect(vertex.in_edges, nil, target)
    @graph.remove_vertex(vertex)
  end

  @graph
end

#on_unit_def(sexpr) ⇒ Object



14
15
16
# File 'lib/gisele/analysis/compiling/ast2graph.rb', line 14

def on_unit_def(sexpr)
  apply(sexpr[1])
end

#on_while_st(sexpr) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/gisele/analysis/compiling/ast2graph.rb', line 99

def on_while_st(sexpr)
  cond, dost, = sexpr.sexpr_body

  entry, exit = entry_and_exit(sexpr)

  diamond = add_vertex(sexpr)
  connect(entry, diamond)

  c_entry, c_exit = apply(sexpr.last)

  connect(diamond, exit,    false_ast_sexpr)
  connect(diamond, c_entry, true_ast_sexpr)
  connect(c_exit, diamond)

  [entry, exit]
end