Class: Furnace::CFG::Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg, label = nil, insns = [], cti = nil, target_labels = [], exception_label = nil) ⇒ Node

Returns a new instance of Node.



13
14
15
16
17
18
19
20
21
22
# File 'lib/furnace/cfg/node.rb', line 13

def initialize(cfg, label=nil, insns=[], cti=nil,
        target_labels=[], exception_label=nil)
  @cfg, @label  = cfg, label

  @instructions = insns
  @control_transfer_instruction = cti

  @target_labels   = target_labels
  @exception_label = exception_label
end

Instance Attribute Details

#cfgObject (readonly)

Returns the value of attribute cfg.



3
4
5
# File 'lib/furnace/cfg/node.rb', line 3

def cfg
  @cfg
end

#control_transfer_instructionObject Also known as: cti

Returns the value of attribute control_transfer_instruction.



6
7
8
# File 'lib/furnace/cfg/node.rb', line 6

def control_transfer_instruction
  @control_transfer_instruction
end

#exception_labelObject

Returns the value of attribute exception_label.



5
6
7
# File 'lib/furnace/cfg/node.rb', line 5

def exception_label
  @exception_label
end

#instructionsObject Also known as: insns

Returns the value of attribute instructions.



6
7
8
# File 'lib/furnace/cfg/node.rb', line 6

def instructions
  @instructions
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/furnace/cfg/node.rb', line 3

def label
  @label
end

#target_labelsObject

Returns the value of attribute target_labels.



5
6
7
# File 'lib/furnace/cfg/node.rb', line 5

def target_labels
  @target_labels
end

Instance Method Details

#==(other) ⇒ Object



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

def ==(other)
  other.is_a?(Node) && self.label == other.label
end

#exceptionObject



42
43
44
# File 'lib/furnace/cfg/node.rb', line 42

def exception
  @cfg.find_node @exception_label if @exception_label
end

#exception_source_labelsObject



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

def exception_source_labels
  exception_sources.map &:label
end

#exception_sourcesObject



50
51
52
# File 'lib/furnace/cfg/node.rb', line 50

def exception_sources
  @cfg.sources_for(self, true)
end

#exits?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/furnace/cfg/node.rb', line 54

def exits?
  targets == [@cfg.exit]
end

#inspectObject



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/furnace/cfg/node.rb', line 62

def inspect
  if @label && @instructions
    "<#{@label}:#{@instructions.join ", "}>"
  elsif @label
    "<#{@label}>"
  elsif @insns
    "<!unlabeled>"
  else
    "<!exit>"
  end
end

#source_labelsObject



34
35
36
# File 'lib/furnace/cfg/node.rb', line 34

def source_labels
  sources.map &:label
end

#sourcesObject



38
39
40
# File 'lib/furnace/cfg/node.rb', line 38

def sources
  @cfg.sources_for(self)
end

#targetsObject



28
29
30
31
32
# File 'lib/furnace/cfg/node.rb', line 28

def targets
  @target_labels.map do |label|
    @cfg.find_node label
  end.freeze
end