Class: Crokus::BasicBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/crokus/cfg.rb

Constant Summary collapse

@@id =
-1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(infos = {}) ⇒ BasicBlock

Returns a new instance of BasicBlock.



50
51
52
53
54
55
56
# File 'lib/crokus/cfg.rb', line 50

def initialize infos={}
  @@id+=1
  @id="L"+@@id.to_s
  @stmts=[]
  @succs=[]
  @infos=infos
end

Instance Attribute Details

#idObject Also known as: label

Returns the value of attribute id.



46
47
48
# File 'lib/crokus/cfg.rb', line 46

def id
  @id
end

#infosObject

Returns the value of attribute infos.



47
48
49
# File 'lib/crokus/cfg.rb', line 47

def infos
  @infos
end

#stmtsObject

Returns the value of attribute stmts.



46
47
48
# File 'lib/crokus/cfg.rb', line 46

def stmts
  @stmts
end

#succsObject

Returns the value of attribute succs.



46
47
48
# File 'lib/crokus/cfg.rb', line 46

def succs
  @succs
end

Instance Method Details

#<<(e) ⇒ Object



58
59
60
# File 'lib/crokus/cfg.rb', line 58

def <<(e)
  @stmts << e
end

#code4dotObject



80
81
82
83
# File 'lib/crokus/cfg.rb', line 80

def code4dot
  @ppr||=PrettyPrinter.new
  @stmts.compact.collect{|stmt| stmt.accept(@ppr)}.join("\n")
end

#falseBranchObject



73
74
75
76
77
78
# File 'lib/crokus/cfg.rb', line 73

def falseBranch
  unless @succs.size==2
    raise "request for falseBranch failed because #{@succs.size} branch(es) found. Strange."
  end
  return @succs.last
end

#nextBranchObject



85
86
87
# File 'lib/crokus/cfg.rb', line 85

def nextBranch
  @succs.first
end

#sizeObject



89
90
91
# File 'lib/crokus/cfg.rb', line 89

def size
  @stmts.size
end

#to(bb) ⇒ Object



62
63
64
# File 'lib/crokus/cfg.rb', line 62

def to bb
  @succs << bb
end

#trueBranchObject



66
67
68
69
70
71
# File 'lib/crokus/cfg.rb', line 66

def trueBranch
  unless @succs.size==2
    raise "request for trueBranch failed because #{@succs.size} branch(es) found. Strange."
  end
  return @succs.first
end