Class: Origen::Registers::Placeholder

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/registers.rb

Overview

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).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, name, attributes) ⇒ Placeholder

Returns a new instance of Placeholder.



138
139
140
141
142
143
# File 'lib/origen/registers.rb', line 138

def initialize(owner, name, attributes)
  @owner = owner
  @name = name
  @attributes = attributes
  @feature = attributes[:feature] if attributes.key?(:feature)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



249
250
251
# File 'lib/origen/registers.rb', line 249

def method_missing(method, *args, &block)
  materialize.send(method, *args, &block)
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



135
136
137
# File 'lib/origen/registers.rb', line 135

def attributes
  @attributes
end

#featureObject (readonly)

Returns the value of attribute feature.



135
136
137
# File 'lib/origen/registers.rb', line 135

def feature
  @feature
end

#nameObject (readonly) Also known as: id

Returns the value of attribute name.



135
136
137
# File 'lib/origen/registers.rb', line 135

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



135
136
137
# File 'lib/origen/registers.rb', line 135

def owner
  @owner
end

Instance Method Details

#cloneObject



261
262
263
# File 'lib/origen/registers.rb', line 261

def clone
  materialize.clone
end

#contains_bits?Boolean

Returns:

  • (Boolean)


269
270
271
# File 'lib/origen/registers.rb', line 269

def contains_bits?
  true
end

#dupObject



265
266
267
# File 'lib/origen/registers.rb', line 265

def dup
  materialize.dup
end

#enabled?Boolean

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

Returns:

  • (Boolean)


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/origen/registers.rb', line 152

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
      return 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
      return value
    end
  else
    return true
  end
end

#enabled_by_feature?(name = nil) ⇒ Boolean Also known as: has_feature_constraint?

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

Returns:

  • (Boolean)


218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/origen/registers.rb', line 218

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
      return false
    else
      return feature == name
    end
  end
end

#freezeObject



245
246
247
# File 'lib/origen/registers.rb', line 245

def freeze
  materialize.freeze
end

#inspectObject

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



237
238
239
# File 'lib/origen/registers.rb', line 237

def inspect
  materialize.inspect
end

#is_a?(klass) ⇒ Boolean

Make this appear like a reg to any application code

Returns:

  • (Boolean)


146
147
148
149
# File 'lib/origen/registers.rb', line 146

def is_a?(klass)
  klass == Origen::Registers::Reg ||
    klass == self.class
end

#materializeObject



257
258
259
# File 'lib/origen/registers.rb', line 257

def materialize
  owner.instantiate_reg(name, attributes)
end

#resetObject

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



242
243
# File 'lib/origen/registers.rb', line 242

def reset
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


253
254
255
# File 'lib/origen/registers.rb', line 253

def respond_to?(method, include_private = false)
  materialize.respond_to?(method, include_private)
end

#to_json(*args) ⇒ Object



273
274
275
# File 'lib/origen/registers.rb', line 273

def to_json(*args)
  materialize.to_json(*args)
end