class Origen::Registers::Placeholder

Instantiating registers can be quite expensive, this object is a placeholder for a register and will transform into one automatically when it is required to (i.e. whenever a register method is called on it).

Attributes

attributes[R]
feature[R]
id[R]
name[R]
owner[R]

Public Class Methods

new(owner, name, attributes) click to toggle source
# File lib/origen/registers.rb, line 136
def initialize(owner, name, attributes)
  @owner = owner
  @name = name
  @attributes = attributes
  @feature = attributes[:_feature] if attributes.key?(:_feature)

  # Give reg.new a way to tell if coming from Placeholder
  if attributes[:bit_info].is_a? Hash
    attributes[:bit_info][:from_placeholder] = true
  end
end

Public Instance Methods

clone() click to toggle source
# File lib/origen/registers.rb, line 264
def clone
  materialize.clone
end
contains_bits?() click to toggle source
# File lib/origen/registers.rb, line 272
def contains_bits?
  true
end
dup() click to toggle source
# File lib/origen/registers.rb, line 268
def dup
  materialize.dup
end
enabled?() click to toggle source

Returns true if the register is enabled by a feature of owner.

# File lib/origen/registers.rb, line 155
def enabled?
  if feature
    value = false
    current_owner = self
    if feature.class == Array
      feature.each do |f|
        current_owner = self
        loop do
          if current_owner.respond_to?(:owner)
            current_owner = current_owner.owner
            if current_owner.respond_to?(:has_feature?)
              if current_owner.has_feature?(f)
                value = true
                break
              end
            end
          else # if current owner does not have a owner
            value = false
            break
          end
        end # loop end
        unless value
          if Origen.top_level && \
             Origen.top_level.respond_to?(:has_feature?) && \
             Origen.top_level.has_feature?(f)
            value = true
            unless value
              break
            end
          end
        end
        unless value
          break # break if feature not found and return false
        end
      end # iterated through all features in array
      value
    else # if feature.class != Array
      loop do
        if current_owner.respond_to?(:owner)
          current_owner = current_owner.owner
          if current_owner.respond_to?(:has_feature?)
            if current_owner.has_feature?(feature)
              value = true
              break
            end
          end
        else # if current owner does not have a owner
          value = false
          break
        end
      end # loop end
      unless value
        if Origen.top_level && \
           Origen.top_level.respond_to?(:has_feature?) && \
           Origen.top_level.has_feature?(feature)
          value = true
        end
      end
      value
    end
  else
    true
  end
end
enabled_by_feature?(name = nil) click to toggle source

Returns true if the register is constrained by the given/any feature

# File lib/origen/registers.rb, line 221
def enabled_by_feature?(name = nil)
  if !name
    !!feature
  else
    if feature.class == Array
      feature.each do |f|
        if f == name
          return true
        end
      end
      false
    else
      feature == name
    end
  end
end
Also aliased as: has_feature_constraint?
freeze() click to toggle source
# File lib/origen/registers.rb, line 248
def freeze
  materialize.freeze
end
has_feature_constraint?(name = nil)
Alias for: enabled_by_feature?
inspect() click to toggle source

Make it look like a reg in the console to avoid confusion

# File lib/origen/registers.rb, line 240
def inspect
  materialize.inspect
end
is_a?(klass) click to toggle source

Make this appear like a reg to any application code

# File lib/origen/registers.rb, line 149
def is_a?(klass)
  klass == Origen::Registers::Reg ||
    klass == self.class
end
materialize() click to toggle source
# File lib/origen/registers.rb, line 260
def materialize
  owner.instantiate_reg(name, attributes)
end
method_missing(method, *args, &block) click to toggle source
# File lib/origen/registers.rb, line 252
def method_missing(method, *args, &block)
  materialize.send(method, *args, &block)
end
reset() click to toggle source

Don’t need to act on reset, an un-materialized reg is by default already reset

# File lib/origen/registers.rb, line 245
def reset
end
respond_to?(method, include_private = false) click to toggle source
# File lib/origen/registers.rb, line 256
def respond_to?(method, include_private = false)
  materialize.respond_to?(method, include_private)
end
to_json(*args) click to toggle source
# File lib/origen/registers.rb, line 276
def to_json(*args)
  materialize.to_json(*args)
end