Module: Origen::Parameters

Extended by:
ActiveSupport::Concern
Defined in:
lib/origen/parameters.rb,
lib/origen/parameters/set.rb,
lib/origen/parameters/live.rb,
lib/origen/parameters/missing.rb

Defined Under Namespace

Modules: ClassMethods Classes: Live, Missing, Set

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#currentObject

Returns the value of attribute current



10
11
12
# File 'lib/origen/parameters.rb', line 10

def current
  @current
end

Class Method Details

.redefine(model, name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
77
78
79
# File 'lib/origen/parameters.rb', line 73

def self.redefine(model, name)
  @transaction_redefine = true
  model._parameter_sets.delete(name)
  @transaction_data[model][name][:definitions].each { |options, block| model.define_params(name, options, &block) }
  @transaction_data[model][name][:children].each { |model, name| redefine(model, name) }
  @transaction_redefine = false
end

.start_transactionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
38
39
# File 'lib/origen/parameters.rb', line 34

def self.start_transaction
  @transaction_data = {}
  @transaction_open = true
  @transaction_counter ||= 0
  @transaction_counter += 1
end

.stop_transactionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/origen/parameters.rb', line 42

def self.stop_transaction
  @transaction_counter -= 1
  if @transaction_counter == 0
    # Now finalize (freeze) all parameter sets we have just defined, this was deferred at define time due
    # to running within a transaction
    @transaction_data.each do |model, parameter_sets|
      parameter_sets.keys.each do |name|
        model._parameter_sets[name].finalize
      end
    end
    @transaction_data = nil
    @transaction_open = false
  end
end

.transactionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Any define_params blocks contained within the given block will be allowed to be re-opened later in the block to override existing parameter settings or to add new ones.

This is not allowed normally since already-defined child parameter sets could have referenced the original parameter and they would not reflect the final value after re-opening the parent parameter set.

By defining the parameters within this block, Origen will keep track of relationships between parameter sets and any time a parent is changed the definitions of existing children will be re-executed to ensure that they reflect the new values.

This is initially intended to support the concept of a app/parameters/application.rb being used to define baseline parameter sets, and then target-specific files can then override them.



27
28
29
30
31
# File 'lib/origen/parameters.rb', line 27

def self.transaction
  start_transaction
  yield
  stop_transaction
end

.transaction_dataObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/origen/parameters.rb', line 58

def self.transaction_data
  @transaction_data
end

.transaction_openObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
# File 'lib/origen/parameters.rb', line 63

def self.transaction_open
  @transaction_open
end

.transaction_redefineObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
# File 'lib/origen/parameters.rb', line 68

def self.transaction_redefine
  @transaction_redefine
end

Instance Method Details

#_live_parameter_requested?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


202
203
204
# File 'lib/origen/parameters.rb', line 202

def _live_parameter_requested?
  @_live_parameter_requested
end

#_parameter_currentObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/origen/parameters.rb', line 178

def _parameter_current
  if path = self.class.parameters_context
    case path
    when :top, :dut
      Origen.top_level._parameter_current
    else
      eval(path)._parameter_current
    end
  else
    @_parameter_current || :default
  end
end

#_parameter_setsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



192
193
194
# File 'lib/origen/parameters.rb', line 192

def _parameter_sets
  @_parameter_sets ||= {}
end

#_request_live_parameterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



197
198
199
# File 'lib/origen/parameters.rb', line 197

def _request_live_parameter
  @_live_parameter_requested = true
end

#define_params(name, options = {}, &block) ⇒ Object Also known as: define_parameters



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/origen/parameters.rb', line 103

def define_params(name, options = {}, &block)
  name = name.to_sym
  if _parameter_sets[name] && !Origen::Parameters.transaction_open
    fail "Parameter set '#{name}' cannot be re-opened once originally defined!"
  else
    if Origen::Parameters.transaction_open && !Origen::Parameters.transaction_redefine
      define_params_transaction[self] ||= {}
      define_params_transaction[self][name] ||= { children: ::Set[], definitions: [] }
      define_params_transaction[self][name][:definitions] << [options.dup, block]
      redefine_children = define_params_transaction[self][name][:children] if _parameter_sets[name]
    end
    if _parameter_sets[name]
      defaults_already_set = true
    else
      _parameter_sets[name] = Origen::Parameters::Set.new(top_level: true, owner: self)
    end
    if options[:inherit]
      kontext = _validate_parameter_set_name(options[:inherit])
      parent = kontext[:obj]._parameter_sets[kontext[:context]]
      if Origen::Parameters.transaction_open && !Origen::Parameters.transaction_redefine
        define_params_transaction[kontext[:obj]][kontext[:context]][:children] << [self, name]
      end
      _parameter_sets[name].copy_defaults_from(parent) unless defaults_already_set
      _parameter_sets[name].define(parent, &block)
    else
      _parameter_sets[name].define(&block)
    end
    if redefine_children
      redefine_children.each { |model, set_name| Origen::Parameters.redefine(model, set_name) }
    end
  end
  _parameter_sets[name]
end

#define_params_transactionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



99
100
101
# File 'lib/origen/parameters.rb', line 99

def define_params_transaction
  Origen::Parameters.transaction_data
end

#has_params?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/origen/parameters.rb', line 161

def has_params?
  _parameter_sets.empty? ? false : true
end

#param?(name) ⇒ Boolean

Return value of param if it exists, nil otherwise.

Returns:

  • (Boolean)


166
167
168
169
170
171
172
173
174
175
# File 'lib/origen/parameters.rb', line 166

def param?(name)
  _param = name.to_s =~ /^params./ ? name.to_s : 'params.' + name.to_s
  begin
    val = eval("self.#{_param}")
  rescue
    nil
  else
    val
  end
end

#params(context = nil) ⇒ Object Also known as: parameters



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

def params(context = nil)
  @_live_parameter_requested = false
  context ||= _parameter_current
  _parameter_sets[context] || Missing.new(owner: self)
end

#params=(name) ⇒ Object Also known as: parameters=



152
153
154
155
156
157
158
# File 'lib/origen/parameters.rb', line 152

def params=(name)
  # Don't validate on setting this as this object could be used to set
  # the context on some other object, therefore validate later if someone tries
  # to access the params on this object
  # _validate_parameter_set_name(name)
  @_parameter_current = name
end

#with_params(name, _options = {}) ⇒ Object



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

def with_params(name, _options = {})
  orig = _parameter_current
  self.params = name
  yield
  self.params = orig
end