lib/origen/sub_blocks.rb in origen-0.30.0 vs lib/origen/sub_blocks.rb in origen-0.31.0
- old
+ new
@@ -4,14 +4,20 @@
# is instantiated
#
# @api private
def init_sub_blocks(*args)
options = args.find { |a| a.is_a?(Hash) }
+ @custom_attrs = (options ? options.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 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) ||
+ @reg_base_address = options.delete(:reg_base_address) ||
options.delete(:base_address) || options.delete(:base) || 0
if options[:_instance]
if @reg_base_address.is_a?(Array)
@reg_base_address = @reg_base_address[options[:_instance]]
elsif options[:base_address_step]
@@ -28,10 +34,24 @@
send("#{k}=", v)
end
end
end
+ # Returns the default
+ def self.lazy?
+ @lazy || false
+ end
+
+ def self.lazy=(value)
+ @lazy = value
+ end
+
+ # Returns a hash containing all options that were passed to the sub_block definition
+ def custom_attrs
+ @custom_attrs
+ end
+
module Domains
def domain(name, options = {})
domains[name] = Origen::Registers::Domain.new(name, options)
end
@@ -280,11 +300,16 @@
sub_blocks[name] = block
end
define_singleton_method name do
get_sub_block(name)
end
- block
+ if options.key?(:lazy)
+ lazy = options[:lazy]
+ else
+ lazy = Origen::SubBlocks.lazy?
+ end
+ lazy ? block : block.materialize
end
end
def namespace
self.class.to_s.sub(/::[^:]*$/, '')
@@ -346,15 +371,16 @@
end
block
end
def ==(obj)
- materialize == obj
+ if obj.is_a?(Placeholder)
+ materialize == obj.materialize
+ else
+ materialize == obj
+ end
end
-
- def !=(obj)
- materialize != obj
- end
+ alias_method :equal?, :==
def freeze
materialize.freeze
end