Class: Origen::Registers::Placeholder
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
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#feature ⇒ Object
readonly
Returns the value of attribute feature.
-
#name ⇒ Object
(also: #id)
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
- #clone ⇒ Object
- #contains_bits? ⇒ Boolean
- #dup ⇒ Object
-
#enabled? ⇒ Boolean
Returns true if the register is enabled by a feature of owner.
-
#enabled_by_feature?(name = nil) ⇒ Boolean
(also: #has_feature_constraint?)
Returns true if the register is constrained by the given/any feature.
- #freeze ⇒ Object
-
#initialize(owner, name, attributes) ⇒ Placeholder
constructor
A new instance of Placeholder.
-
#inspect ⇒ Object
Make it look like a reg in the console to avoid confusion.
-
#is_a?(klass) ⇒ Boolean
Make this appear like a reg to any application code.
- #materialize ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
-
#reset ⇒ Object
Don’t need to act on reset, an un-materialized reg is by default already reset.
- #respond_to?(method) ⇒ Boolean
Constructor Details
#initialize(owner, name, attributes) ⇒ Placeholder
Returns a new instance of Placeholder.
112 113 114 115 116 117 |
# File 'lib/origen/registers.rb', line 112 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
223 224 225 |
# File 'lib/origen/registers.rb', line 223 def method_missing(method, *args, &block) materialize.send(method, *args, &block) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
109 110 111 |
# File 'lib/origen/registers.rb', line 109 def attributes @attributes end |
#feature ⇒ Object (readonly)
Returns the value of attribute feature.
109 110 111 |
# File 'lib/origen/registers.rb', line 109 def feature @feature end |
#name ⇒ Object (readonly) Also known as: id
Returns the value of attribute name.
109 110 111 |
# File 'lib/origen/registers.rb', line 109 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
109 110 111 |
# File 'lib/origen/registers.rb', line 109 def owner @owner end |
Instance Method Details
#clone ⇒ Object
235 236 237 |
# File 'lib/origen/registers.rb', line 235 def clone materialize.clone end |
#contains_bits? ⇒ Boolean
243 244 245 |
# File 'lib/origen/registers.rb', line 243 def contains_bits? true end |
#dup ⇒ Object
239 240 241 |
# File 'lib/origen/registers.rb', line 239 def dup materialize.dup end |
#enabled? ⇒ Boolean
Returns true if the register is enabled by a feature of owner.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 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 |
# File 'lib/origen/registers.rb', line 126 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
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/origen/registers.rb', line 192 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 |
#freeze ⇒ Object
219 220 221 |
# File 'lib/origen/registers.rb', line 219 def freeze materialize.freeze end |
#inspect ⇒ Object
Make it look like a reg in the console to avoid confusion
211 212 213 |
# File 'lib/origen/registers.rb', line 211 def inspect materialize.inspect end |
#is_a?(klass) ⇒ Boolean
Make this appear like a reg to any application code
120 121 122 123 |
# File 'lib/origen/registers.rb', line 120 def is_a?(klass) klass == Origen::Registers::Reg || klass == self.class end |
#materialize ⇒ Object
231 232 233 |
# File 'lib/origen/registers.rb', line 231 def materialize owner.instantiate_reg(name, attributes) end |
#reset ⇒ Object
Don’t need to act on reset, an un-materialized reg is by default already reset
216 217 |
# File 'lib/origen/registers.rb', line 216 def reset end |
#respond_to?(method) ⇒ Boolean
227 228 229 |
# File 'lib/origen/registers.rb', line 227 def respond_to?(method) materialize.respond_to?(method) end |