Skip to content

Commit 3ff6b77

Browse files
committed
Merge branch 'master' into 1.5.x
2 parents f93d3b1 + f90de0f commit 3ff6b77

File tree

5 files changed

+92
-13
lines changed

5 files changed

+92
-13
lines changed

src/main/scala/chisel3/iotesters/Driver.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ object Driver {
2929
*/
3030
def execute[T <: MultiIOModule](
3131
dutGenerator: () => T,
32-
optionsManager: TesterOptionsManager
32+
optionsManager: TesterOptionsManager,
33+
firrtlSourceOverride: Option[String] = None
3334
)
3435
(
3536
testerGen: T => PeekPokeTester[T]
@@ -48,11 +49,11 @@ object Driver {
4849

4950
val (dut, backend) = testerOptions.backendName match {
5051
case "firrtl" =>
51-
setupFirrtlTerpBackend(dutGenerator, optionsManager)
52+
setupFirrtlTerpBackend(dutGenerator, optionsManager, firrtlSourceOverride)
5253
case "treadle" =>
5354
setupTreadleBackend(dutGenerator, optionsManager)
5455
case "verilator" =>
55-
setupVerilatorBackend(dutGenerator, optionsManager)
56+
setupVerilatorBackend(dutGenerator, optionsManager, firrtlSourceOverride)
5657
case "ivl" =>
5758
setupIVLBackend(dutGenerator, optionsManager)
5859
case "vcs" =>

src/main/scala/chisel3/iotesters/FirrtlTerpBackend.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ private[iotesters] class FirrtlTerpBackend(
118118
private[iotesters] object setupFirrtlTerpBackend {
119119
def apply[T <: MultiIOModule](
120120
dutGen: () => T,
121-
optionsManager: TesterOptionsManager = new TesterOptionsManager): (T, Backend) = {
121+
optionsManager: TesterOptionsManager = new TesterOptionsManager with HasInterpreterOptions,
122+
firrtlSourceOverride: Option[String] = None
123+
): (T, Backend) = {
122124

123125
// the backend must be firrtl if we are here, therefore we want the firrtl compiler
124126
optionsManager.firrtlOptions = optionsManager.firrtlOptions.copy(compilerName = "low")
@@ -137,7 +139,8 @@ private[iotesters] object setupFirrtlTerpBackend {
137139
val dut = getTopModule(circuit).asInstanceOf[T]
138140
firrtlExecutionResult match {
139141
case FirrtlExecutionSuccess(_, compiledFirrtl) =>
140-
(dut, new FirrtlTerpBackend(dut, compiledFirrtl, optionsManager = optionsManager))
142+
val firrtlText = firrtlSourceOverride.getOrElse(compiledFirrtl)
143+
(dut, new FirrtlTerpBackend(dut, firrtlText, optionsManager = optionsManager))
141144
case FirrtlExecutionFailure(message) =>
142145
throw new Exception(s"FirrtlBackend: failed firrlt compile message: $message")
143146
}

src/main/scala/chisel3/iotesters/TreadleBackend.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ package chisel3.iotesters
55
import chisel3.internal.InstanceId
66
import chisel3.stage.{ChiselCircuitAnnotation, ChiselStage}
77
import chisel3.{Element, MemBase, MultiIOModule, assert}
8-
import firrtl.{AnnotationSeq, LowForm}
8+
import firrtl.stage.CompilerAnnotation
9+
import firrtl.{AnnotationSeq, annoSeqToSeq}
910
import treadle.stage.TreadleTesterPhase
10-
import treadle.{TreadleFirrtlFormHint, TreadleTester, TreadleTesterAnnotation}
11+
import treadle.{TreadleTester, TreadleTesterAnnotation}
1112

1213
private[iotesters] class TreadleBackend(
1314
dut: MultiIOModule,
@@ -70,7 +71,8 @@ extends Backend(_seed = System.currentTimeMillis()) {
7071
val got = treadleTester.peek(name)
7172
val good = got == expected
7273
if (verbose || !good) logger info
73-
s"""EXPECT AT $stepNumber $msg $name got ${bigIntToStr(got, base)} expected ${bigIntToStr(expected, base)}""" +
74+
s"""EXPECT AT $stepNumber $msg $name got ${bigIntToStr(got, base)}""" +
75+
s""" expected ${bigIntToStr(expected, base)}""" +
7476
s""" ${if (good) "PASS" else "FAIL"}"""
7577
if(good) treadleTester.expectationsMet += 1
7678
good
@@ -146,10 +148,11 @@ private[iotesters] object setupTreadleBackend {
146148
val dut = getTopModule(circuit).asInstanceOf[T]
147149

148150
// This generates the firrtl circuit needed by the TreadleTesterPhase
149-
annotationSeq = (new ChiselStage).run(annotationSeq)
151+
// Uses low compiler to avoid padWidths changing Dshl to Dshlw which blows up CheckTypes
152+
annotationSeq = (new ChiselStage).execute(Array("-X", "low"), annotationSeq)
150153

151154
// This generates a TreadleTesterAnnotation with a treadle tester instance
152-
annotationSeq = (new TreadleTesterPhase).transform(annotationSeq :+ TreadleFirrtlFormHint(LowForm))
155+
annotationSeq = (new TreadleTesterPhase).transform(annotationSeq)
153156

154157
val treadleTester = annotationSeq.collectFirst { case TreadleTesterAnnotation(t) => t }.getOrElse(
155158
throw new Exception(
@@ -161,4 +164,3 @@ private[iotesters] object setupTreadleBackend {
161164
(dut, new TreadleBackend(dut, treadleTester))
162165
}
163166
}
164-

src/main/scala/chisel3/iotesters/VerilatorBackend.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ int main(int argc, char **argv, char **env) {
205205
}
206206

207207
private[iotesters] object setupVerilatorBackend {
208-
def apply[T <: MultiIOModule](dutGen: () => T, optionsManager: TesterOptionsManager): (T, Backend) = {
208+
def apply[T <: MultiIOModule](dutGen: () => T,
209+
optionsManager: TesterOptionsManager,
210+
firrtlSourceOverride: Option[String] = None): (T, Backend) = {
209211
import firrtl.{ChirrtlForm, CircuitState}
210212

211213
optionsManager.makeTargetDir()
@@ -220,7 +222,8 @@ private[iotesters] object setupVerilatorBackend {
220222
chisel3.Driver.execute(optionsManager, dutGen) match {
221223
case ChiselExecutionSuccess(Some(circuit), emitted, _) =>
222224

223-
val chirrtl = firrtl.Parser.parse(emitted)
225+
val chirrtlSource = firrtlSourceOverride.getOrElse(emitted)
226+
val chirrtl = firrtl.Parser.parse(chirrtlSource)
224227
val dut = getTopModule(circuit).asInstanceOf[T]
225228

226229
val suppressVerilatorVCD = optionsManager.testerOptions.generateVcdOutput == "off"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2020 The Regents of the University of California (Regents)
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package chisel3.iotesters
18+
19+
import chisel3._
20+
import chisel3.experimental.Interval
21+
import chisel3.internal.firrtl.IntervalRange
22+
import org.scalatest.{FreeSpec, Matchers}
23+
24+
class IntervalShifter(val bitWidth: Int, val binaryPoint: Int, val fixedShiftSize: Int) extends Module {
25+
val dynamicShifterWidth = 3
26+
27+
val io = IO(new Bundle {
28+
val inValue = Input(Interval(IntervalRange(bitWidth.W, binaryPoint.BP)))
29+
val dynamicShiftValue = Input(UInt(dynamicShifterWidth.W))
30+
val shiftRightResult: Option[Interval] = if(fixedShiftSize < bitWidth) {
31+
Some(Output(Interval(IntervalRange((bitWidth - fixedShiftSize).W, binaryPoint.BP))))
32+
}
33+
else {
34+
None
35+
}
36+
val shiftLeftResult = Output(Interval(IntervalRange((bitWidth + fixedShiftSize).W, binaryPoint.BP)))
37+
val dynamicShiftRightResult = Output(Interval(IntervalRange(bitWidth.W, binaryPoint.BP)))
38+
val dynamicShiftLeftResult = Output(
39+
Interval(IntervalRange((bitWidth + (1 << dynamicShifterWidth) - 1).W, binaryPoint.BP))
40+
)
41+
})
42+
43+
io.shiftLeftResult := io.inValue << fixedShiftSize
44+
io.shiftRightResult.foreach { out =>
45+
out := (io.inValue >> fixedShiftSize).asInstanceOf[Interval].squeeze(out)
46+
}
47+
io.dynamicShiftLeftResult := io.inValue << io.dynamicShiftValue
48+
io.dynamicShiftRightResult := io.inValue >> io.dynamicShiftValue
49+
}
50+
51+
class IntervalShiftLeftSpec extends FreeSpec with Matchers {
52+
"Shift left of interval used to create Dshlw problem in CheckTypes" in {
53+
val backendName = "treadle"
54+
val defaultWidth = 8
55+
val binaryPoint = 0
56+
val fixedShiftSize = 1
57+
Driver.execute(
58+
Array(
59+
"--backend-name", backendName,
60+
"--target-dir", s"test_run_dir/interval-shift-test-$fixedShiftSize-$binaryPoint.BP"
61+
),
62+
() => new IntervalShifter(bitWidth = 8, binaryPoint = binaryPoint, fixedShiftSize = fixedShiftSize)
63+
64+
) { c =>
65+
new PeekPokeTester(c) {
66+
67+
}
68+
} should be(true)
69+
}
70+
}

0 commit comments

Comments
 (0)