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
144
145
146
147
148
# 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)

  # 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



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

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



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

def clone
  materialize.clone
end

#contains_bits?Boolean

Returns:

  • (Boolean)


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

def contains_bits?
  true
end

#dupObject



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

def dup
  materialize.dup
end

#enabled?Boolean

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

Returns:

  • (Boolean)


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
219
220
# File 'lib/origen/registers.rb', line 157

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)


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/origen/registers.rb', line 223

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



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

def freeze
  materialize.freeze
end

#inspectObject

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



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

def inspect
  materialize.inspect
end

#is_a?(klass) ⇒ Boolean

Make this appear like a reg to any application code

Returns:

  • (Boolean)


151
152
153
154
# File 'lib/origen/registers.rb', line 151

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

#materializeObject



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

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



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

def reset
end

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

Returns:

  • (Boolean)


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

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

#to_json(*args) ⇒ Object



278
279
280
# File 'lib/origen/registers.rb', line 278

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