Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Treadle can find clock with some other name #351

Merged
merged 1 commit into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/main/scala/treadle/TreadleTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package treadle

import java.io.PrintWriter
import java.util.Calendar

import firrtl.AnnotationSeq
import firrtl.ir.ClockType
import firrtl.options.StageOptions
import firrtl.options.Viewer.view
import firrtl.stage.OutputFileAnnotation
Expand Down Expand Up @@ -74,8 +74,23 @@ class TreadleTester(annotationSeq: AnnotationSeq) {

val startTime: Long = System.nanoTime()

private def findTopLevelClocks() = {
engine.symbolTable.symbols.collect {
case symbol if symbol.firrtlType == ClockType && !(symbol.name.contains(".") || symbol.name.endsWith("/prev")) =>
symbol
}.toList
}

val clockInfoList: Seq[ClockInfo] = if (clockInfo.isEmpty) {
if (engine.symbolTable.contains("clock")) {
val topClocks = findTopLevelClocks()

if (topClocks.length > 2) {
println(s"Warning: multiple top level clocks found without any ClockInfo information, is this intentional?")
}

if (topClocks.length == 1) {
Seq(ClockInfo(topClocks.head.name))
} else if (engine.symbolTable.contains("clock")) {
Seq(ClockInfo())
} else if (engine.symbolTable.contains("clk")) {
Seq(ClockInfo("clk"))
Expand Down
21 changes: 21 additions & 0 deletions src/test/scala/treadle/ClockSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ class ClockSpec extends AnyFreeSpec with Matchers with LazyLogging {
}
}

"clocks can have names other than clock" in {
val input =
"""
|circuit OddClockName :
| module OddClockName :
| input tardigrade : Clock
| input reset : UInt<1>
| output out2 : UInt<8>
|
| reg reg2 : UInt<8>, tardigrade with : (reset => (reset, UInt<8>("h0")))
| reg2 <= add(reg2, UInt<8>("h01"))
| out2 <= reg2
|
""".stripMargin

TreadleTestHarness(Seq(FirrtlSourceAnnotation(input))) { tester =>
tester.step(100)
tester.expect("out2", 100)
}
}

"clocks must behave properly behind validif" in {
val input =
"""
Expand Down