Class: Crokus::CFGPrinter
- Inherits:
-
Object
- Object
- Crokus::CFGPrinter
- Defined in:
- lib/crokus/cfg_printer.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
Instance Method Summary collapse
- #clean4dot(str) ⇒ Object
- #footer ⇒ Object
- #header ⇒ Object
- #id(bb) ⇒ Object
- #print(cfg, pos = 0) ⇒ Object
- #visitRec(bb) ⇒ Object
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
7 8 9 |
# File 'lib/crokus/cfg_printer.rb', line 7 def code @code end |
Instance Method Details
#clean4dot(str) ⇒ Object
67 68 69 70 |
# File 'lib/crokus/cfg_printer.rb', line 67 def clean4dot str str=str.gsub(/\\n\"/,'"') str=str.gsub(/"/,'\"') end |
#footer ⇒ Object
42 43 44 |
# File 'lib/crokus/cfg_printer.rb', line 42 def "}" end |
#header ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/crokus/cfg_printer.rb', line 20 def header ret=Code.new ret << "digraph ControlFlowGraph {" ret.indent=2 ret << 'forcelabels=true;' ret << 'graph [ label="",' ret << ' bgcolor="white",' ret << ' fontname="Arail",' ret << ' rankdir="TB"]' ret.newline ret << 'node [ fontname="Arial",' ret << ' shape="box",' ret << ' style="filled",' ret << ' fillcolor="AliceBlue"]' ret.newline ret << 'edge [ fontname="Arial",' ret << ' color="Blue",' ret << ' dir="forward"]' ret.newline ret end |
#id(bb) ⇒ Object
63 64 65 |
# File 'lib/crokus/cfg_printer.rb', line 63 def id bb "bb_#{bb.id.to_s}" end |
#print(cfg, pos = 0) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/crokus/cfg_printer.rb', line 9 def print cfg,pos=0 @code=Code.new @code << header @visited=[] visitRec(cfg.starter) @code << dot_name="cfg_#{cfg.name}.dot" @code.save_as dot_name puts " "*pos+"|--[+] graphviz file saved as '#{dot_name}'" end |
#visitRec(bb) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/crokus/cfg_printer.rb', line 46 def visitRec bb while !@visited.include?(bb) @visited << bb c_code=bb.code4dot c_code=clean4dot(c_code) code << "#{id(bb)} [label=\"#{c_code}\",shape=rectangle, xlabel=#{bb.label}]" bb.succs.each_with_index do |succ,idx| if bb.succs.size>1 label = (idx==0 ? "true" : "false") label = "[label=#{label}]" end code << "#{id(bb)} -> #{id(succ)} #{label}" visitRec(succ) end end end |