Module: Origen::SubBlocks

Includes:
Domains, Parent, Path, RegBaseAddress
Defined in:
lib/origen/sub_blocks.rb

Defined Under Namespace

Modules: Domains, Parent, Path, RegBaseAddress

Instance Method Summary collapse

Methods included from Path

#abs_path, #abs_path=, #path, #path=, #path_var

Methods included from RegBaseAddress

#base_address, #reg_base_address, #reg_base_address_for_domain

Methods included from Parent

#owner=, #parent

Methods included from Domains

#domain, #domain_specified?, #domains

Instance Method Details

#all_sub_blocksObject

Returns an array containing all descendant child objects of the given sub-block, i.e. this returns an array containing children’s children as well

Note that this returns an array instead of a hash since there could be naming collisions in the hash keys



210
211
212
213
214
# File 'lib/origen/sub_blocks.rb', line 210

def all_sub_blocks
  @all_sub_blocks ||= begin
    (sub_blocks_array + sub_blocks_array.map(&:all_sub_blocks)).flatten
  end
end

#delete_sub_blocksObject

Delete all sub_blocks by emptyig the Hash



196
197
198
# File 'lib/origen/sub_blocks.rb', line 196

def delete_sub_blocks
  @sub_blocks = {}
end

#init_sub_blocks(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This will be called whenever an object that includes this module is instantiated



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/origen/sub_blocks.rb', line 7

def init_sub_blocks(*args)
  options = args.find { |a| a.is_a?(Hash) }
  if options
    # Using reg_base_address for storage to avoid class with the original Origen base
    # address API, but will accept any of these
    @reg_base_address = options.delete(:reg_base_address) || options.delete(:reg_base_address) ||
                        options.delete(:base_address) || options.delete(:base) || 0
    @domain_names = [options.delete(:domain) || options.delete(:domains)].flatten.compact
    @domain_specified = !@domain_names.empty?
    @path = options.delete(:path)
    @abs_path = options.delete(:abs_path) || options.delete(:absolute_path)
  end
  if is_a?(SubBlock)
    options.each do |k, v|
      send("#{k}=", v)
    end
  end
end

#namespaceObject



268
269
270
# File 'lib/origen/sub_blocks.rb', line 268

def namespace
  self.class.to_s.sub(/::[^:]*$/, '')
end

#owns_registers?Boolean

Returns true if the given sub block owns at least one register

Returns:

  • (Boolean)


217
218
219
220
221
222
223
# File 'lib/origen/sub_blocks.rb', line 217

def owns_registers?
  if regs
    regs.is_a?(Origen::Registers::RegCollection) && !regs.empty?
  else
    false
  end
end

#sub_block(name, options = {}) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/origen/sub_blocks.rb', line 225

def sub_block(name, options = {})
  class_name = options.delete(:class_name)
  if class_name
    begin
      klass = eval("::#{namespace}::#{class_name}")
    rescue
      begin
        klass = eval(class_name)
      rescue
        begin
          klass = eval("#{self.class}::#{class_name}")
        rescue
          puts "Could not find class: #{class_name}"
          raise 'Unknown sub block class!'
        end
      end
    end
  else
    klass = Origen::SubBlock
  end
  unless klass.respond_to?(:includes_origen_model)
    puts 'Any class which is to be instantiated as a sub_block must include Origen::Model,'
    puts "add this to #{klass}:"
    puts ''
    puts '  include Origen::Model'
    puts ''
    fail 'Sub block does not include Origen::Model!'
  end
  block = klass.new(options.merge(parent: self))
  block.name = name
  sub_blocks[name] = block
  if respond_to?(name)
    # puts "Tried to create a sub-block named #{name} in #{self.class}, but it already has a method with this name!"
    # puts "To avoid confusion rename one of them and try again!"
    # raise "Non-unique sub-block name!"
  else
    define_singleton_method name do
      sub_blocks[name]
    end
  end
  block
end

#sub_blocksObject Also known as: children

Returns a hash containing all immediate children of the given sub-block



190
191
192
# File 'lib/origen/sub_blocks.rb', line 190

def sub_blocks
  @sub_blocks ||= {}.with_indifferent_access
end

#sub_blocks_arrayObject Also known as: children_array



200
201
202
# File 'lib/origen/sub_blocks.rb', line 200

def sub_blocks_array
  sub_blocks.map { |_name, sub_block| sub_block }
end