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, metadata = {}) ⇒ Node

Returns a new instance of Node.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/furnace/cfg/node.rb', line 15

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

  @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

#metadataObject

Returns the value of attribute metadata.



8
9
10
# File 'lib/furnace/cfg/node.rb', line 8

def 
  @metadata
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



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

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

#exceptionObject



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

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

#exception_source_labelsObject



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

def exception_source_labels
  exception_sources.map &:label
end

#exception_sourcesObject



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

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

#exits?Boolean

Returns:

  • (Boolean)


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

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

#inspectObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/furnace/cfg/node.rb', line 66

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

#source_labelsObject



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

def source_labels
  sources.map &:label
end

#sourcesObject



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

def sources
  @cfg.sources_for(self)
end

#targetsObject



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

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