Class: Origen::Netlist::List

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/netlist/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(top_level) ⇒ List

Returns a new instance of List.



9
10
11
12
# File 'lib/origen/netlist/list.rb', line 9

def initialize(top_level)
  @top_level = top_level
  @table = {}
end

Instance Attribute Details

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/origen/netlist/list.rb', line 4

def table
  @table
end

#top_levelObject (readonly) Also known as: parent, owner

Returns the value of attribute top_level.



4
5
6
# File 'lib/origen/netlist/list.rb', line 4

def top_level
  @top_level
end

Instance Method Details

#connect(a, b = nil, &block) ⇒ Object

Connect two paths together in the netlist, one can be a numeric value to represent a logic level connection



16
17
18
19
20
21
22
23
# File 'lib/origen/netlist/list.rb', line 16

def connect(a, b = nil, &block)
  b ||= block
  align(a, b) do |path, index, target|
    table[path] ||= {}
    table[path][index] ||= []
    table[path][index] << target
  end
end

#data_bit(path, index, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/origen/netlist/list.rb', line 25

def data_bit(path, index, options = {})
  bits = data_bits(path, index, options)
  if bits.size > 1
    fail "Multiple data bit connections found for node #{path}[#{index}]"
  elsif bits.size == 0
    return undefined
  end

  bits.first
end

#data_bits(path, index, options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/origen/netlist/list.rb', line 36

def data_bits(path, index, options = {})
  processed_paths = options[:processed_paths] || []
  bits = []
  ['*', index].each do |i|
    unless processed_paths.include?("#{path}[#{i}]")
      processed_paths << "#{path}[#{i}]"
      vals = (table[path] || {})[i] || []
      # Also consider anything attached directly to the requested path, e.g. a
      # drive value applied to a port
      vals << "#{path}[#{i}]" if i != '*' && !options[:sublevel]
      vals.each do |val|
        if val.is_a?(Proc)
          from_proc = true
          val = val.call(index)
        else
          from_proc = false
        end
        if val.is_a?(Integer)
          bits << Registers::Bit.new(nil, index, access: :ro, data: (i == '*' && !from_proc) ? val[index] : val)
        elsif val
          vp, vi = *to_v(val)
          bc = eval("top_level.#{vp}[#{vi || index}]")
          if bc.is_a?(Registers::BitCollection)
            bits << bc.bit
          elsif bc.is_a?(Ports::Section) && bc.drive_value
            bits << Registers::Bit.new(nil, index, access: :ro, data: bc.drive_value)
          else
            bits += data_bits(vp, vi || index, processed_paths: processed_paths, sublevel: true) || []
          end
        end
      end
    end
  end
  bits.uniq
end