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.



136
137
138
139
140
141
142
143
144
145
146
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



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

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

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



133
134
135
# File 'lib/origen/registers.rb', line 133

def attributes
  @attributes
end

#featureObject (readonly)

Returns the value of attribute feature.



133
134
135
# File 'lib/origen/registers.rb', line 133

def feature
  @feature
end

#nameObject (readonly) Also known as: id

Returns the value of attribute name.



133
134
135
# File 'lib/origen/registers.rb', line 133

def name
  @name
end

#ownerObject (readonly)

Returns the value of attribute owner.



133
134
135
# File 'lib/origen/registers.rb', line 133

def owner
  @owner
end

Instance Method Details

#cloneObject



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

def clone
  materialize.clone
end

#contains_bits?Boolean

Returns:

  • (Boolean)


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

def contains_bits?
  true
end

#dupObject



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

def dup
  materialize.dup
end

#enabled?Boolean

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

Returns:

  • (Boolean)


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
216
217
218
# 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) ⇒ Boolean Also known as: has_feature_constraint?

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

Returns:

  • (Boolean)


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# 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

#freezeObject



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

def freeze
  materialize.freeze
end

#inspectObject

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



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

def inspect
  materialize.inspect
end

#is_a?(klass) ⇒ Boolean

Make this appear like a reg to any application code

Returns:

  • (Boolean)


149
150
151
152
# File 'lib/origen/registers.rb', line 149

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

#materializeObject



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

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



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

def reset
end

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

Returns:

  • (Boolean)


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

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

#to_json(*args) ⇒ Object



276
277
278
# File 'lib/origen/registers.rb', line 276

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