Class: Udb::AbstractCondition Abstract

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/udb/condition.rb,
lib/udb/condition.rb

Overview

This class is abstract.

It cannot be directly instantiated. Subclasses must implement the ‘abstract` methods below.

Base class to represent any condition in the UDB data, and to connect/test them

Conditions constructed from UDB data need context to be evaluated; for example, a condition that requires extension A to be implemented implies that Zaamo and Zalrsc must also be implemented.

We add this implied information in a step called expand. Many methods of AbstractCondition take an optional ‘expand:` argument that, when true, expands the condition before operating on it.

Instance Method Summary collapse

Instance Method Details

#&(other) ⇒ AbstractCondition

This method is abstract.

logical conjunction

Parameters:

Returns:



362
# File 'lib/udb/condition.rb', line 362

def &(other); end

#-@AbstractCondition

This method is abstract.

logical negation

we use - instead of ! for negation to avoid ambiguous situations like:

!condition.satisfiable?
   (is this "negate condition is satisfiable" or "condition is unsatisfiable")

Returns:



375
# File 'lib/udb/condition.rb', line 375

def -@; end

#always_implies?(other_condition) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


271
272
273
# File 'lib/udb/condition.rb', line 271

def always_implies?(other_condition)
  other_condition.covered_by?(self)
end

#compatible?(other) ⇒ Boolean

is is possible for this condition and other to be simultaneously true?

Parameters:

Returns:

  • (Boolean)


213
214
215
# File 'lib/udb/condition.rb', line 213

def compatible?(other)
  (self & other).satisfiable?
end

#could_be_satisfied_by_cfg_arch?(cfg_arch) ⇒ Boolean

for the given config arch, is condition satisfiable?

Parameters:

Returns:

  • (Boolean)


242
243
244
# File 'lib/udb/condition.rb', line 242

def could_be_satisfied_by_cfg_arch?(cfg_arch)
  satisfied_by_cfg_arch?(cfg_arch) != SatisfiedResult::No
end

#covered_by?(other_condition) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/udb/condition.rb', line 256

def covered_by?(other_condition)
  # cover means other_condition always implies self
  # can test that by seeing if the contradiction is satisfiable, i.e.:
  # if other_condition -> self , contradition would be other_condition & not self
  contradiction = LogicNode.new(
    LogicNodeType::And,
    [
      other_condition.to_logic_tree(expand: true),
      LogicNode.new(LogicNodeType::Not, [to_logic_tree(expand: true)])
    ]
  )
  !contradiction.satisfiable?
end

#empty?Boolean

This method is abstract.

returns true if this condition is always true or always false (does not depend on extensions or parameters)

Returns:

  • (Boolean)


129
# File 'lib/udb/condition.rb', line 129

def empty?; end

#equivalent?(other) ⇒ Boolean

is this condition logically equivalent to other? this is true logical equivalence, not just syntatic equivalence, e.g.:

(a || a) is equivalent to (a)

Parameters:

Returns:

  • (Boolean)


250
251
252
253
# File 'lib/udb/condition.rb', line 250

def equivalent?(other)
  contradition = -(self.implies(other) & other.implies(self))
  contradition.unsatisfiable?
end

#ext_req_terms(expand:) ⇒ Array<ExtensionRequirement>

return list of all extension requirements in the condition

if expand is true, expand the condition to include transitive requirements

Parameters:

  • expand (Boolean)

Returns:



187
188
189
190
191
192
193
194
195
# File 'lib/udb/condition.rb', line 187

def ext_req_terms(expand:)
  if expand
    @expanded_ext_req_terms ||=
      to_logic_tree(expand:).terms.grep(ExtensionTerm).map { |term| term.to_ext_req(@cfg_arch) }
  else
    @unexpanded_ext_req_terms ||=
      to_logic_tree(expand:).terms.grep(ExtensionTerm).map { |term| term.to_ext_req(@cfg_arch) }
  end
end

#has_extension_requirement?Boolean

This method is abstract.

true if the condition references any extension

Returns:

  • (Boolean)


281
# File 'lib/udb/condition.rb', line 281

def has_extension_requirement?; end

#has_param?Boolean

This method is abstract.

true if the condition references any parameter

Returns:

  • (Boolean)


277
# File 'lib/udb/condition.rb', line 277

def has_param?; end

#implied_extension_conflicts(expand: true) ⇒ Array<ConditionalExtensionRequirement>

This method is abstract.

inversion of implied_extension_requirements

Parameters:

  • expand (Boolean) (defaults to: true)

Returns:



358
# File 'lib/udb/condition.rb', line 358

def implied_extension_conflicts(expand: true); end

#implied_extension_requirements(expand: true) ⇒ Array<ConditionalExtensionRequirement>

This method is abstract.

assuming that the condition represents an extension dependency, return the specified extensions along with the condition under which they apply

specifically, this returns the complete list of positive terms (terms that are not negated in solution) of requirements, along with a conditionthat must hold for condition to be satisfied when the positive term is met

This list is not transitive; if an implication I1 implies another extension I2, only I1 shows up in the list

Examples:

given the equation (representing implications of the "C" extension):
   Zca@1.0.0 AND (!F OR Zcf@1.0.0) AND (!D OR Zcd@1.0.0)

return:
  [
     { ext_req: Zca@1.0.0, cond: True },
     { ext_req: Zcf@1.0.0, cond: !F },
     { ext_req: Zcd@1.0.0, cond: !D }
  ]
given the equation
  Zc AND ((Zc1 AND Zc2) OR (!Zcond))

return
  [
    { ext_ver: Zc,  cond True},
    { ext_ver: Zc1, cond: !Zcond},
    { ext_ver: Zc2, cond: !Zcond}
  ]

Parameters:

  • expand (Boolean) (defaults to: true)

Returns:



354
# File 'lib/udb/condition.rb', line 354

def implied_extension_requirements(expand: true); end

#implies(other) ⇒ AbstractCondition

logical implication

a.implies(b) means:

if a; then b

Parameters:

Returns:



383
384
385
# File 'lib/udb/condition.rb', line 383

def implies(other)
  -self | other
end

#mentions?(term, expand: true) ⇒ Boolean

is this condition in any way affected by term?

Parameters:

Returns:

  • (Boolean)


149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/udb/condition.rb', line 149

def mentions?(term, expand: true)
  to_logic_tree(expand:).terms.any? do |t|
    case t
    when ExtensionTerm
      (term.is_a?(Extension) || term.is_a?(ExtensionVersion) || term.is_a?(ExtensionRequirement)) && (term.name == t.name)
    when ParameterTerm
      (term.is_a?(Parameter) || term.is_a?(ParameterWithValue)) && (term.name == t.name)
    else
      false
    end
  end
end

#mentions_xlen?(expand: true) ⇒ Boolean

Parameters:

  • expand (Boolean) (defaults to: true)

Returns:

  • (Boolean)


163
164
165
166
167
# File 'lib/udb/condition.rb', line 163

def mentions_xlen?(expand: true)
  to_logic_tree(expand:).terms.any? do |t|
    t.is_a?(XlenTerm)
  end
end

#minimize(expand: true) ⇒ AbstractCondition

This method is abstract.

minimizes the condition. see LogicNode#minimize when expand is false, minimize the condition without expanding first when expand is true, expand the condition and then minimize

Parameters:

  • expand (Boolean) (defaults to: true)

Returns:



287
# File 'lib/udb/condition.rb', line 287

def minimize(expand: true); end

#param_terms(expand:) ⇒ Array<Parameter>

return list of all parameters in the condition

if expand is true, expand the condition to include transitive requirements

Parameters:

  • expand (Boolean)

Returns:



201
202
203
204
205
206
207
208
209
# File 'lib/udb/condition.rb', line 201

def param_terms(expand:)
  if expand
    @expanded_param_terms ||=
      to_logic_tree(expand:).terms.grep(ParameterTerm).map { |term| @cfg_arch.param(term.name) }
  else
    @unexpanded_param_terms ||=
      to_logic_tree(expand:).terms.grep(ParameterTerm).map { |term| @cfg_arch.param(term.name) }
  end
end

#partial_eval(ext_reqs: [], expand: true) ⇒ AbstractCondition

This method is abstract.

Parameters:

Returns:



222
# File 'lib/udb/condition.rb', line 222

def partial_eval(ext_reqs: [], expand: true); end

#partially_evaluate_for_params(cfg_arch, expand:) ⇒ AbstractCondition

This method is abstract.

partially evaluate by replacing any known parameter terms with true/false, and returning a new condition

Parameters:

Returns:



227
# File 'lib/udb/condition.rb', line 227

def partially_evaluate_for_params(cfg_arch, expand:); end

#rv32_only?Boolean

is this condition only satisfied when xlen == 32?

Returns:

  • (Boolean)


171
172
173
174
# File 'lib/udb/condition.rb', line 171

def rv32_only?
  (self & Condition.not(Condition::Xlen32, @cfg_arch)).unsatisfiable? & \
  (self & Condition.not(Condition::Xlen64, @cfg_arch)).satisfiable?
end

#rv64_only?Boolean

is this condition only satisfied when xlen == 64?

Returns:

  • (Boolean)


178
179
180
181
# File 'lib/udb/condition.rb', line 178

def rv64_only?
  (self & Condition.not(Condition::Xlen64, @cfg_arch)).unsatisfiable? & \
  (self & Condition.not(Condition::Xlen32, @cfg_arch)).satisfiable?
end

#satisfiability_depends_on_ext_req?(_ext_req, include_requirements: false) ⇒ Boolean

This method is abstract.

If ext_req is not satisfied, is condition satisfiable? When include_requirements is true, also assume that the ext_req’s requirements are not met

Parameters:

Returns:

  • (Boolean)


238
# File 'lib/udb/condition.rb', line 238

def satisfiability_depends_on_ext_req?(_ext_req, include_requirements: false); end

#satisfiable?Boolean

This method is abstract.

is this condition satisfiable?

Returns:

  • (Boolean)


141
# File 'lib/udb/condition.rb', line 141

def satisfiable?; end

#satisfied_by_cfg_arch?(_cfg_arch) ⇒ SatisfiedResult

This method is abstract.

Returns if the condition is, possibly is, or is definately not satisfied by cfg_arch.

Parameters:

Returns:

  • (SatisfiedResult)

    if the condition is, possibly is, or is definately not satisfied by cfg_arch



219
# File 'lib/udb/condition.rb', line 219

def satisfied_by_cfg_arch?(_cfg_arch); end

#satisfied_by_ext_req?(ext_req, include_requirements: false) ⇒ Boolean

This method is abstract.

is condition satisfied if ext_req is the only thing defined?

When include_requirements is true, expand the condition before evaluating

Parameters:

Returns:

  • (Boolean)


233
# File 'lib/udb/condition.rb', line 233

def satisfied_by_ext_req?(ext_req, include_requirements: false); end

#to_asciidocString

This method is abstract.

string representation of condition in Asciidoc

Returns:

  • (String)


319
# File 'lib/udb/condition.rb', line 319

def to_asciidoc; end

#to_hHash{String => T.untyped}, Boolean

This method is abstract.

convert condition into UDB-compatible hash

Returns:

  • (Hash{String => T.untyped}, Boolean)


291
# File 'lib/udb/condition.rb', line 291

def to_h; end

#to_idl(cfg_arch) ⇒ String

This method is abstract.

convert condition into valid IDL

Parameters:

Returns:

  • (String)


301
# File 'lib/udb/condition.rb', line 301

def to_idl(cfg_arch); end

#to_logic_tree(expand:) ⇒ LogicNode

This method is abstract.

convert to the underlying LogicNode-based tree

Parameters:

  • expand (Boolean)

Returns:



133
# File 'lib/udb/condition.rb', line 133

def to_logic_tree(expand:); end

#to_logic_tree_internalLogicNode

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.

This method is abstract.

Returns:



137
# File 'lib/udb/condition.rb', line 137

def to_logic_tree_internal; end

#to_s(expand: false) ⇒ String

This method is abstract.

string representation when expand is true, return the full expanded condition

Parameters:

  • expand (Boolean) (defaults to: false)

Returns:

  • (String)


306
# File 'lib/udb/condition.rb', line 306

def to_s(expand: false); end

#to_s_prettyString

This method is abstract.

condition in prose

Returns:

  • (String)


310
# File 'lib/udb/condition.rb', line 310

def to_s_pretty; end

#to_s_with_value(cfg_arch, expand:) ⇒ String

This method is abstract.

string representation, annotated with actual values of terms where known useful for debugging

Parameters:

Returns:

  • (String)


315
# File 'lib/udb/condition.rb', line 315

def to_s_with_value(cfg_arch, expand:); end

#to_yamlString

convert condition into UDB-compatible YAML string

Returns:

  • (String)


295
296
297
# File 'lib/udb/condition.rb', line 295

def to_yaml
  YAML.dump(to_h)
end

#unsatisfiable?Boolean

This method is abstract.

is this condition unsatisfiable?

Returns:

  • (Boolean)


145
# File 'lib/udb/condition.rb', line 145

def unsatisfiable?; end

#|(other) ⇒ AbstractCondition

This method is abstract.

logical disjunction

Parameters:

Returns:



366
# File 'lib/udb/condition.rb', line 366

def |(other); end