aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/constraint/Constraint.scala
blob: 87d15737079a34b4a4e10adf4047195e23a6deaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// SPDX-License-Identifier: Apache-2.0

package firrtl.constraint

/** Trait for all Constraint Solver expressions */
trait Constraint {
  def serialize: String
  def map(f: Constraint => Constraint): Constraint
  val children: Vector[Constraint]
  def reduce(): Constraint
}

/** Trait for constraints with more than one argument */
trait MultiAry extends Constraint {
  def op(a:     IsKnown, b:          IsKnown): IsKnown
  def merge(b1: Option[IsKnown], b2: Option[IsKnown]): Option[IsKnown] = (b1, b2) match {
    case (Some(x), Some(y)) => Some(op(x, y))
    case (_, y: Some[_]) => y
    case (x: Some[_], _) => x
    case _ => None
  }
}