Module: Origen::SubBlocks
- Includes:
- Domains, Parent, Path, RegBaseAddress
- Defined in:
- lib/origen/sub_blocks.rb
Defined Under Namespace
Modules: Domains, Parent, Path, RegBaseAddress Classes: Placeholder
Class Method Summary collapse
- .lazy=(value) ⇒ Object
-
.lazy? ⇒ Boolean
Returns the default.
Instance Method Summary collapse
-
#all_sub_blocks ⇒ Object
Returns an array containing all descendant child objects of the given sub-block, i.e.
-
#custom_attrs ⇒ Object
Returns a hash containing all options that were passed to the sub_block definition.
-
#delete_sub_blocks ⇒ Object
Delete all sub_blocks by emptying the Hash.
- #has_fuses? ⇒ Boolean
- #has_tests? ⇒ Boolean
-
#init_sub_blocks(*args) ⇒ Object
private
This will be called whenever an object that includes this module is instantiated.
- #namespace ⇒ Object
-
#owns_registers? ⇒ Boolean
(also: #has_regs?)
Returns true if the given sub block owns at least one register.
- #sub_block(name, options = {}) ⇒ Object
-
#sub_blocks(*args) ⇒ Object
(also: #children)
Returns a hash containing all immediate children of the given sub-block.
- #sub_blocks_array ⇒ Object (also: #children_array)
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
Methods included from Domains
#domain, #domain_specified?, #domains
Class Method Details
.lazy=(value) ⇒ Object
44 45 46 |
# File 'lib/origen/sub_blocks.rb', line 44 def self.lazy=(value) @lazy = value end |
.lazy? ⇒ Boolean
Returns the default
40 41 42 |
# File 'lib/origen/sub_blocks.rb', line 40 def self.lazy? @lazy || false end |
Instance Method Details
#all_sub_blocks ⇒ Object
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
250 251 252 253 254 |
# File 'lib/origen/sub_blocks.rb', line 250 def all_sub_blocks @all_sub_blocks ||= begin (sub_blocks_array + sub_blocks_array.map(&:all_sub_blocks)).flatten end end |
#custom_attrs ⇒ Object
Returns a hash containing all options that were passed to the sub_block definition
49 50 51 |
# File 'lib/origen/sub_blocks.rb', line 49 def custom_attrs @custom_attrs end |
#delete_sub_blocks ⇒ Object
Delete all sub_blocks by emptying the Hash
236 237 238 |
# File 'lib/origen/sub_blocks.rb', line 236 def delete_sub_blocks @sub_blocks = {} end |
#has_fuses? ⇒ Boolean
266 267 268 |
# File 'lib/origen/sub_blocks.rb', line 266 def has_fuses? fuses.empty? ? false : true end |
#has_tests? ⇒ Boolean
270 271 272 |
# File 'lib/origen/sub_blocks.rb', line 270 def has_tests? tests.empty? ? false : true 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 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/origen/sub_blocks.rb', line 7 def init_sub_blocks(*args) = args.find { |a| a.is_a?(Hash) } @custom_attrs = ( ? .dup : {}).with_indifferent_access # Delete these keys which are either meta data added by Origen or are already covered by # dedicated methods %w(parent name base_address reg_base_address base).each do |key| @custom_attrs.delete(key) end if # 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 = .delete(:reg_base_address) || .delete(:base_address) || .delete(:base) || 0 if [:_instance] if @reg_base_address.is_a?(Array) @reg_base_address = @reg_base_address[[:_instance]] elsif [:base_address_step] @reg_base_address = @reg_base_address + ([:_instance] * [:base_address_step]) end end @domain_names = [.delete(:domain) || .delete(:domains)].flatten.compact @domain_specified = !@domain_names.empty? @path = .delete(:path) @abs_path = .delete(:abs_path) || .delete(:absolute_path) end if is_a?(SubBlock) .each do |k, v| send("#{k}=", v) end end end |
#namespace ⇒ Object
314 315 316 |
# File 'lib/origen/sub_blocks.rb', line 314 def namespace self.class.to_s.sub(/::[^:]*$/, '') end |
#owns_registers? ⇒ Boolean Also known as: has_regs?
Returns true if the given sub block owns at least one register
257 258 259 260 261 262 263 |
# File 'lib/origen/sub_blocks.rb', line 257 def owns_registers? if regs regs.is_a?(Origen::Registers::RegCollection) && !regs.empty? else false end end |
#sub_block(name, options = {}) ⇒ Object
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/origen/sub_blocks.rb', line 274 def sub_block(name, = {}) if i = .delete(:instances) a = [] [:_instance] = i i.times do |j| o = .dup o[:_instance] = j a << sub_block("#{name}#{j}", o) end define_singleton_method "#{name}s" do a end a else block = Placeholder.new(self, name, ) if sub_blocks[name] # Allow additional attributes to be added to an existing sub-block if it hasn't # been instantiated yet. This is not supported yet for instantiated sub-blocks since # there are probably a lot more corner-cases to consider, and hopefully no one will # really need this anyway. if sub_blocks[name].is_a?(Placeholder) sub_blocks[name].add_attributes() else fail "You have already defined a sub-block named #{name} within class #{self.class}" end else sub_blocks[name] = block end define_singleton_method name do get_sub_block(name) end if .key?(:lazy) lazy = [:lazy] else lazy = Origen::SubBlocks.lazy? end lazy ? block : block.materialize end end |
#sub_blocks(*args) ⇒ Object Also known as: children
Returns a hash containing all immediate children of the given sub-block
226 227 228 229 230 231 232 |
# File 'lib/origen/sub_blocks.rb', line 226 def sub_blocks(*args) if args.empty? @sub_blocks ||= {}.with_indifferent_access else sub_block(*args) end end |
#sub_blocks_array ⇒ Object Also known as: children_array
240 241 242 |
# File 'lib/origen/sub_blocks.rb', line 240 def sub_blocks_array sub_blocks.map { |_name, sub_block| sub_block } end |