From cf5019e2d2208099445c1f7e0530a86abf0efabc Mon Sep 17 00:00:00 2001 From: Kevin Laeufer Date: Mon, 26 Jul 2021 18:09:06 -0700 Subject: ir: make HashCode.toHashString public (#2302) This will allow chiseltest to save the hash code to disk for the purpose of caching simulation binaries.--- src/main/scala/firrtl/ir/StructuralHash.scala | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/scala/firrtl/ir/StructuralHash.scala b/src/main/scala/firrtl/ir/StructuralHash.scala index 20c63e4e..26e7d210 100644 --- a/src/main/scala/firrtl/ir/StructuralHash.scala +++ b/src/main/scala/firrtl/ir/StructuralHash.scala @@ -115,16 +115,20 @@ object StructuralHash { } trait HashCode { - protected val str: String - override def hashCode(): Int = str.hashCode + + /** String representation of the hash code. + * Two instances of [[HashCode]] are equal if and only if their toHashString values are equal. + */ + def toHashString: String + override def hashCode(): Int = toHashString.hashCode override def equals(obj: Any): Boolean = obj match { - case hashCode: HashCode => this.str.equals(hashCode.str) + case hashCode: HashCode => this.toHashString.equals(hashCode.toHashString) case _ => false } } private class MDHashCode(code: Array[Byte]) extends HashCode { - protected override val str: String = code.map(b => f"${b.toInt & 0xff}%02x").mkString("") + override val toHashString: String = code.map(b => f"${b.toInt & 0xff}%02x").mkString("") } /** Generic hashing interface which allows us to use different backends to trade of speed and collision resistance */ -- cgit v1.2.3