aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/constraint/Constraint.scala
blob: 1a3bc21a50b9b545c270060bff386734352f70aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// See LICENSE for license details.

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
  }
}