Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ object OpaqueTypeSpec {
class Boxed[T <: Data](gen: T) extends MaybeBoxed[T] {
def boxed = true
lazy val elements = SeqMap("underlying" -> gen)
def underlying = elements.head._2
def underlying = elements.head._2.asInstanceOf[T]
}
class Unboxed[T <: Data](gen: T) extends MaybeBoxed[T] with OpaqueType {
def boxed = false
lazy val elements = SeqMap("" -> gen)
def underlying = elements.head._2
def underlying = elements.head._2.asInstanceOf[T]
}

class MaybeNoAsUInt(noAsUInt: Boolean) extends Record with OpaqueType {
Expand Down
2 changes: 1 addition & 1 deletion src/test/scala-2/chiselTests/interface/Drivers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.File
import chisel3.RawModule
import chisel3.stage.ChiselGeneratorAnnotation
import circt.stage.{ChiselStage, FirtoolOption}
import firrtl.AnnotationSeq
import firrtl.{seqToAnnoSeq, AnnotationSeq}
import firrtl.options.{StageError, StageUtils}
import sys.process._

Expand Down
2 changes: 1 addition & 1 deletion src/test/scala-2/chiselTests/simulator/SimulatorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import chisel3.simulator._
import chisel3.util.{HasExtModuleInline, HasExtModulePath, HasExtModuleResource}
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.must.Matchers
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper
// import org.scalatest.matchers.should.Matchers.convertToStringShouldWrapperForVerb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please don't commit commented out code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is a tricky one. the scalatest API is subtly different between Scala 2 and 3 leading to an either-or situation as to which ShouldWrapper to use. will revisit and fix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check that ScalaTest doesn't already have a way to deal with this--it would be pretty bush league for such a popular library to screw this up. If they dont then we can polyfill it ourselves by adding a type alias for one or the other in the version-specific sources (e.g. in src/main/scala-2 define org.scalatest.matchers.should.Matchers.convertToStringShouldWrapperForVerb as a type alias for org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper).

import svsim._

class VerilatorSimulator(val workspacePath: String) extends Simulator[verilator.Backend] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ object ChiselStageSpec {
}

class RecoverableErrorFakeSourceInfo extends RawModule {
implicit val info = SourceLine("Foo", 3, 10)
implicit val info: SourceLine = SourceLine("Foo", 3, 10)
3.U >> -1
}

class ErrorCaughtByFirtool extends RawModule {
implicit val info = SourceLine("Foo", 3, 10)
implicit val info: SourceLine = SourceLine("Foo", 3, 10)
val w = Wire(UInt(8.W))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package chisel3.stage

import firrtl.options.Viewer.view
import firrtl.RenameMap
import firrtl.{seqToAnnoSeq, RenameMap}

import chisel3.ElaboratedCircuit
import chisel3.stage._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class AdderTreeTester(bitWidth: Int, numsToAdd: List[Int]) extends Module {
val dut = Module(new AdderTree(genType, numsToAdd.size))
dut.io.numIn := VecInit(numsToAdd.map(x => x.asUInt(bitWidth.W)))
val sumCorrect = dut.io.numOut === (numsToAdd.reduce(_ + _) % (1 << bitWidth)).asUInt(bitWidth.W)
assert(sumCorrect)
chisel3.assert(sumCorrect)
stop()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ class AutoClonetypeSpec extends AnyFlatSpec with Matchers {
}
emitCHIRRTL {
new Module {
implicit val x = 8
implicit val x: Int = 8
val in = IO(Input(new MyBundle))
val out = IO(Output(new MyBundle))
out := in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class BlackBoxSpec extends AnyFlatSpec with Matchers with ChiselSim with FileChe
object A extends layer.Layer(layer.LayerConfig.Extract())

sealed trait NoIo { this: BlackBox =>
final val io = IO(new Bundle {})
final val io = chisel3.IO(new Bundle {})
}

// No known layers
Expand Down Expand Up @@ -401,7 +401,7 @@ class BlackBoxSpec extends AnyFlatSpec with Matchers with ChiselSim with FileChe
class Bar extends BlackBox {
final val io = IO {
new Bundle {
val a = Output(probe.Probe(Bool(), layers.Verification))
val a = Output(probe.Probe(Bool(), chisel3.layers.Verification))
}
}
}
Expand All @@ -411,7 +411,7 @@ class BlackBoxSpec extends AnyFlatSpec with Matchers with ChiselSim with FileChe
class Baz extends BlackBox(knownLayers = Seq(A)) {
final val io = IO {
new Bundle {
val a = Output(probe.Probe(Bool(), layers.Verification))
val a = Output(probe.Probe(Bool(), chisel3.layers.Verification))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class BulkConnectSpec extends AnyPropSpec with Matchers {
val chirrtl = ChiselStage.emitCHIRRTL(new Module {
val io: MyBundle = IO(Flipped(new MyBundle))

val bb = Module(new BlackBox {
val bb = Module[BlackBox { def io: MyBundle }](new BlackBox {
val io: MyBundle = IO(Flipped(new MyBundle))
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Decoder(bitpats: List[String]) extends Module {
val inst = Input(UInt(32.W))
val matched = Output(Bool())
})
io.matched := VecInit(bitpats.map(BitPat(_) === io.inst)).reduce(_ || _)
io.matched := VecInit(bitpats.map(BitPat(_) === io.inst).reduce(_ || _))
}

class DecoderTester(pairs: List[(String, String)]) extends Module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package chiselTests

import chisel3._
import circt.stage.ChiselStage
import chisel3.experimental.{fromIntToIntParam, fromStringToStringParam}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers

class LiteralToTargetSpec extends AnyFreeSpec with Matchers {

"Literal Data should fail to be converted to ReferenceTarget" in {

(the[ChiselException] thrownBy {

val ex = the[ChiselException] thrownBy {
class Bar extends RawModule {
val a = 1.U
}
Expand All @@ -23,6 +20,8 @@ class LiteralToTargetSpec extends AnyFreeSpec with Matchers {
}

ChiselStage.emitCHIRRTL(new Foo)
} should have).message("Illegal component name: UInt<1>(0h1) (note: literals are illegal)")
}

ex.getMessage shouldBe "Illegal component name: UInt<1>(0h1) (note: literals are illegal)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package chiselTests

import java.io.{ByteArrayOutputStream, PrintStream}
import logger.{LogLevel, LogLevelAnnotation, Logger}
import firrtl.{annoSeqToSeq, seqToAnnoSeq, AnnotationSeq}

trait LogUtils {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class ModuleWithChoice[T <: Data](
default: => FixedIOBaseModule[T]
)(alternateImpls: Seq[(Case, () => FixedIOBaseModule[T])])
extends Module {
val inst = ModuleChoice(default)(alternateImpls)
val io = IO(inst.cloneType)
val inst: T = ModuleChoice[T](default, alternateImpls)
val io: T = IO(chiselTypeOf(inst))
io <> inst
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import chisel3.stage.ChiselGeneratorAnnotation
import circt.stage.{CIRCTTarget, CIRCTTargetAnnotation, ChiselStage, FirtoolOption}
import firrtl.annotations.NoTargetAnnotation
import firrtl.options.{TargetDirAnnotation, Unserializable}
import firrtl.{annoSeqToSeq, seqToAnnoSeq}
import org.scalatest.matchers.should.Matchers
import org.scalatest.propspec.AnyPropSpec
import scala.io.Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ class SIntOpsSpec extends AnyPropSpec with Matchers with ShiftRightWidthBehavior
}

property("Static right-shift should have a minimum width of 1") {
testShiftRightWidthBehavior(SInt)(chiselMinWidth = 1, firrtlMinWidth = 1)
testSIntShiftRightWidthBehavior(chiselMinWidth = 1, firrtlMinWidth = 1)
}

property("Static right-shift should have width of 0 in Chisel and 1 in FIRRTL with --use-legacy-width") {
val args = Array("--use-legacy-width")

testShiftRightWidthBehavior(SInt)(chiselMinWidth = 0, firrtlMinWidth = 1, args = args)
testSIntShiftRightWidthBehavior(chiselMinWidth = 0, firrtlMinWidth = 1, args = args)

// Focused test to show the mismatch
class TestModule extends Module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SimLogSpec extends AnyFlatSpec with Matchers with FileCheck with ChiselSim
class MyModule extends Module {
val in = IO(Input(UInt(8.W)))
val fd = SimLog.file("logfile.log")
fd.printf("in = %d\n", in)
// fd.printf("in = %d\n", in)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shouldn't be commented out?

}
ChiselStage
.emitCHIRRTL(new MyModule)
Expand Down
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this file has so many lines added. Can you clarify what is going on?

Original file line number Diff line number Diff line change
Expand Up @@ -214,62 +214,100 @@ class UIntLitZeroWidthTester extends Module {
}

trait ShiftRightWidthBehavior extends WidthHelpers {
// The UInt and SInt objects don't share a type, so make one up that they can conform to structurally
type BitsFactory[T <: Bits] = {
def apply(): T
def apply(w: Width): T
def testSIntShiftRightWidthBehavior(chiselMinWidth: Int, firrtlMinWidth: Int, args: Iterable[String] = Nil): Unit = {
assertKnownWidth(4, args) {
val in = IO(Input(SInt(8.W)))
in >> 4
}
assertKnownWidth(chiselMinWidth, args) {
val in = IO(Input(SInt(8.W)))
in >> 8
}
assertKnownWidth(chiselMinWidth, args) {
val in = IO(Input(SInt(8.W)))
in >> 16
}
assertKnownWidth(chiselMinWidth, args) {
val in = IO(Input(SInt(0.W)))
in >> 8
}
assertKnownWidth(chiselMinWidth, args) {
val in = IO(Input(SInt(0.W)))
in >> 0
}
assertInferredWidth(4, args) {
val in = IO(Input(SInt(8.W)))
val w = WireInit(SInt(), in)
w >> 4
}
assertInferredWidth(firrtlMinWidth, args) {
val in = IO(Input(SInt(8.W)))
val w = WireInit(SInt(), in)
w >> 8
}
assertInferredWidth(firrtlMinWidth, args) {
val in = IO(Input(SInt(8.W)))
val w = WireInit(SInt(), in)
w >> 16
}
assertInferredWidth(firrtlMinWidth, args) {
val in = IO(Input(SInt(0.W)))
val w = WireInit(SInt(), in)
w >> 8
}
assertInferredWidth(firrtlMinWidth, args) {
val in = IO(Input(SInt(0.W)))
val w = WireInit(SInt(), in)
w >> 0
}
}

def testShiftRightWidthBehavior[T <: Bits](
factory: BitsFactory[T]
)(chiselMinWidth: Int, firrtlMinWidth: Int, args: Iterable[String] = Nil): Unit = {
def testUIntShiftRightWidthBehavior(chiselMinWidth: Int, firrtlMinWidth: Int, args: Iterable[String] = Nil): Unit = {
assertKnownWidth(4, args) {
val in = IO(Input(factory(8.W)))
val in = IO(Input(UInt(8.W)))
in >> 4
}
assertKnownWidth(chiselMinWidth, args) {
val in = IO(Input(factory(8.W)))
val in = IO(Input(UInt(8.W)))
in >> 8
}
assertKnownWidth(chiselMinWidth, args) {
val in = IO(Input(factory(8.W)))
val in = IO(Input(UInt(8.W)))
in >> 16
}
assertKnownWidth(chiselMinWidth, args) {
val in = IO(Input(factory(0.W)))
val in = IO(Input(UInt(0.W)))
in >> 8
}
assertKnownWidth(chiselMinWidth, args) {
val in = IO(Input(factory(0.W)))
val in = IO(Input(UInt(0.W)))
in >> 0
}
assertInferredWidth(4, args) {
val in = IO(Input(factory(8.W)))
val w = WireInit(factory(), in)
val in = IO(Input(UInt(8.W)))
val w = WireInit(UInt(), in)
w >> 4
}
assertInferredWidth(firrtlMinWidth, args) {
val in = IO(Input(factory(8.W)))
val w = WireInit(factory(), in)
val in = IO(Input(UInt(8.W)))
val w = WireInit(UInt(), in)
w >> 8
}
assertInferredWidth(firrtlMinWidth, args) {
val in = IO(Input(factory(8.W)))
val w = WireInit(factory(), in)
val in = IO(Input(UInt(8.W)))
val w = WireInit(UInt(), in)
w >> 16
}
assertInferredWidth(firrtlMinWidth, args) {
val in = IO(Input(factory(0.W)))
val w = WireInit(factory(), in)
val in = IO(Input(UInt(0.W)))
val w = WireInit(UInt(), in)
w >> 8
}
assertInferredWidth(firrtlMinWidth, args) {
val in = IO(Input(factory(0.W)))
val w = WireInit(factory(), in)
val in = IO(Input(UInt(0.W)))
val w = WireInit(UInt(), in)
w >> 0
}
}

}

class UIntOpsSpec extends AnyPropSpec with Matchers with LogUtils with ShiftRightWidthBehavior with ChiselSim {
Expand Down Expand Up @@ -551,13 +589,13 @@ class UIntOpsSpec extends AnyPropSpec with Matchers with LogUtils with ShiftRigh
}

property("Static right-shift should have a minimum width of 0") {
testShiftRightWidthBehavior(UInt)(chiselMinWidth = 0, firrtlMinWidth = 0)
testUIntShiftRightWidthBehavior(chiselMinWidth = 0, firrtlMinWidth = 0)
}

property("Static right-shift should have width of 0 in Chisel and 1 in FIRRTL with --use-legacy-width") {
val args = Array("--use-legacy-width")

testShiftRightWidthBehavior(UInt)(chiselMinWidth = 0, firrtlMinWidth = 1, args = args)
testUIntShiftRightWidthBehavior(chiselMinWidth = 0, firrtlMinWidth = 1, args = args)

// Focused test to show the mismatch
class TestModule extends Module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package chiselTests.naming

import chisel3._
import chisel3.aop.Select
import chisel3.experimental.prefix
import chisel3.experimental.AffectsChiselName
import chisel3.testing.scalatest.FileCheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package chiselTests.naming

import chisel3._
import chisel3.aop.Select
import chisel3.experimental.{noPrefix, prefix, skipPrefix, AffectsChiselPrefix}
import chisel3.testing.scalatest.FileCheck
import circt.stage.ChiselStage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import chisel3.stage.{ChiselCircuitAnnotation, ChiselGeneratorAnnotation, Design
import firrtl.options.OptionsException
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import firrtl.{annoSeqToSeq, seqToAnnoSeq, AnnotationSeq}

class ChiselAnnotationsSpecFoo extends RawModule {
val in = IO(Input(Bool()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chisel3.RawModule
import chisel3.stage.ChiselGeneratorAnnotation
import chisel3.stage.phases.{AddImplicitOutputAnnotationFile, Elaborate}

import firrtl.AnnotationSeq
import firrtl.{annoSeqToSeq, seqToAnnoSeq, AnnotationSeq}
import firrtl.options.{OutputAnnotationFileAnnotation, Phase}
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chisel3.RawModule
import chisel3.stage.{ChiselGeneratorAnnotation, ChiselOutputFileAnnotation}
import chisel3.stage.phases.{AddImplicitOutputFile, Elaborate}

import firrtl.AnnotationSeq
import firrtl.{annoSeqToSeq, seqToAnnoSeq, AnnotationSeq}
import firrtl.options.{Phase, StageOptions, TargetDirAnnotation}
import firrtl.options.Viewer.view
import org.scalatest.flatspec.AnyFlatSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import chisel3.stage.{ChiselGeneratorAnnotation, ChiselOutputFileAnnotation, Cir
import chisel3.stage.CircuitSerializationAnnotation._
import chisel3.stage.phases.{AddImplicitOutputFile, AddSerializationAnnotations, Elaborate}

import firrtl.AnnotationSeq
import firrtl.{annoSeqToSeq, seqToAnnoSeq, AnnotationSeq}
import firrtl.options.{Dependency, Phase, PhaseManager, TargetDirAnnotation}
import firrtl.options.Viewer.view
import org.scalatest.flatspec.AnyFlatSpec
Expand Down
Loading
Loading