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
-
#all_sub_blocks ⇒ Object
Returns an array containing all descendant child objects of the given sub-block, i.e.
-
#delete_sub_blocks ⇒ Object
Delete all sub_blocks by emptyig the Hash.
-
#init_sub_blocks(*args) ⇒ Object
private
This will be called whenever an object that includes this module is instantiated.
- #namespace ⇒ Object
-
#owns_registers? ⇒ Boolean
Returns true if the given sub block owns at least one register.
- #sub_block(name, options = {}) ⇒ Object
-
#sub_blocks ⇒ 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
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
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_blocks ⇒ Object
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) = args.find { |a| a.is_a?(Hash) } 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(:reg_base_address) || .delete(:base_address) || .delete(:base) || 0 @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
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
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, = {}) class_name = .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(.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_blocks ⇒ Object 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_array ⇒ Object 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 |