Skip to content

Commit

Permalink
Merge pull request #3354 from chipsalliance/3.6master
Browse files Browse the repository at this point in the history
[WIP] Bump master to chisel 3.6
  • Loading branch information
jerryz123 authored Jun 15, 2023
2 parents 0586532 + e13945a commit d78198c
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 77 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.sys.process._

enablePlugins(PackPlugin)

val chiselVersion = "3.5.6"
val chiselVersion = "3.6.0"

lazy val commonSettings = Seq(
organization := "edu.berkeley.cs",
Expand All @@ -15,7 +15,7 @@ lazy val commonSettings = Seq(
traceLevel := 15,
scalacOptions ++= Seq("-deprecation","-unchecked"),
libraryDependencies ++= Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value),
libraryDependencies ++= Seq("org.json4s" %% "json4s-jackson" % "3.6.6"),
libraryDependencies ++= Seq("org.json4s" %% "json4s-native" % "4.0.6"),
libraryDependencies ++= Seq("org.scalatest" %% "scalatest" % "3.2.0" % "test"),
resolvers ++= Seq(
Resolver.sonatypeRepo("snapshots"),
Expand Down
97 changes: 62 additions & 35 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ object hardfloatRocket extends hardfloat.build.hardfloat {
def chisel3IvyDeps = if(chisel3Module.isEmpty) Agg(
common.getVersion("chisel3")
) else Agg.empty[Dep]

def chisel3PluginIvyDeps = if(chisel3Module.isEmpty) Agg(
common.getVersion("chisel3-plugin", cross = true)
) else Agg.empty[Dep]

override def repositories = super.repositories ++ Seq(
MavenRepository("https://oss.sonatype.org/content/repositories/snapshots"),
MavenRepository("https://oss.sonatype.org/content/repositories/releases")
)
}

object rocketchip extends common.CommonRocketChip {
Expand Down Expand Up @@ -78,47 +87,65 @@ object emulator extends mill.Cross[Emulator](
("freechips.rocketchip.system.TestHarness", "freechips.rocketchip.system.MemPortOnlyConfig"),
("freechips.rocketchip.system.TestHarness", "freechips.rocketchip.system.MMIOPortOnlyConfig"),
("freechips.rocketchip.system.TestHarness", "freechips.rocketchip.system.CloneTileConfig"),
("freechips.rocketchip.system.TestHarness", "freechips.rocketchip.system.HypervisorConfig"),
)
class Emulator(top: String, config: String) extends ScalaModule {
override def moduleDeps = Seq(rocketchip)

override def scalaVersion: T[String] = T {
"2.13.10"
}

def spikeRoot = T { envByNameOrRiscv("SPIKE_ROOT") }

def generator = T {
// class path for `moduleDeps` is only a directory, not a jar, which breaks the cache.
// so we need to manually add the class files of `moduleDeps` here.
upstreamCompileOutput()
mill.modules.Jvm.runLocal(
"freechips.rocketchip.system.Generator",
runClasspath().map(_.path),
Seq(
class Emulator(top: String, config: String) extends Module {

object generator extends Module {
def elaborate = T {
os.proc(
mill.modules.Jvm.javaExe,
"-jar",
rocketchip.assembly().path,
"freechips.rocketchip.system.Generator",
"-td", T.dest.toString,
"-T", top,
"-C", config,
),
)
PathRef(T.dest)
).call()
PathRef(T.dest)
}

def chiselAnno = T {
os.walk(elaborate().path).collectFirst { case p if p.last.endsWith("anno.json") => p }.map(PathRef(_)).get
}

def chirrtl = T {
os.walk(elaborate().path).collectFirst { case p if p.last.endsWith("fir") => p }.map(PathRef(_)).get
}
}

def firrtl = T {
val input = generator().path / (config + ".fir")
val output = T.dest / (top + "-" + config + ".v")
mill.modules.Jvm.runLocal(
"firrtl.stage.FirrtlMain",
runClasspath().map(_.path),
Seq(
"-i", input.toString,
"-o", output.toString,
),
)
PathRef(output)
object mfccompiler extends Module {
def compile = T {
os.proc("firtool",
generator.chirrtl().path,
s"--annotation-file=${generator.chiselAnno().path}",
"-disable-infer-rw",
"--disable-annotation-unknown",
"-dedup",
"-O=debug",
"--split-verilog",
"--preserve-values=named",
"--output-annotation-file=mfc.anno.json",
s"-o=${T.dest}"
).call(T.dest)
PathRef(T.dest)
}

def rtls = T {
os.read(compile().path / "filelist.f").split("\n").map(str =>
try {
os.Path(str)
} catch {
case e: IllegalArgumentException if e.getMessage.contains("is not an absolute path") =>
compile().path / str.stripPrefix("./")
}
).filter(p => p.ext == "v" || p.ext == "sv").map(PathRef(_)).toSeq
}
}

object verilator extends Module {
def spikeRoot = T { envByNameOrRiscv("SPIKE_ROOT") }

def csrcDir = T {
PathRef(os.pwd / "src" / "main" / "resources" / "csrc")
}
Expand All @@ -142,7 +169,7 @@ class Emulator(top: String, config: String) extends ScalaModule {
|project(emulator)
|include_directories(${csrcDir().path})
|# plusarg is here
|include_directories(${generator().path})
|include_directories(${generator.elaborate().path})
|link_directories(${spikeRoot() + "/lib"})
|include_directories(${spikeRoot() + "/include"})
|
Expand All @@ -151,7 +178,7 @@ class Emulator(top: String, config: String) extends ScalaModule {
|set(CMAKE_C_COMPILER "clang")
|set(CMAKE_CXX_COMPILER "clang++")
|set(CMAKE_CXX_FLAGS
|"$${CMAKE_CXX_FLAGS} -DVERILATOR -DTEST_HARNESS=VTestHarness -include VTestHarness.h -include verilator.h -include ${generator().path / config + ".plusArgs"}")
|"$${CMAKE_CXX_FLAGS} -DVERILATOR -DTEST_HARNESS=VTestHarness -include VTestHarness.h -include verilator.h -include ${generator.elaborate().path / config + ".plusArgs"}")
|set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|find_package(verilator)
Expand All @@ -165,7 +192,7 @@ class Emulator(top: String, config: String) extends ScalaModule {
|target_link_libraries(emulator PRIVATE fesvr)
|verilate(emulator
| SOURCES
|${firrtl().path}
| ${mfccompiler.rtls().map(_.path.toString).mkString("\n")}
| TOP_MODULE TestHarness
| PREFIX VTestHarness
| VERILATOR_ARGS ${verilatorArgs().mkString(" ")}
Expand Down
11 changes: 8 additions & 3 deletions common.sc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import mill.scalalib.publish._
import coursier.maven.MavenRepository

val defaultVersions = Map(
"chisel3" -> "3.5.6",
"chisel3-plugin" -> "3.5.6"
"chisel3" -> "3.6.0",
"chisel3-plugin" -> "3.6.0"
)

def getVersion(dep: String, org: String = "edu.berkeley.cs", cross: Boolean = false) = {
Expand Down Expand Up @@ -45,6 +45,11 @@ trait CommonRocketChip extends SbtModule with PublishModule {
override def publishVersion = T {
m.publishVersion()
}

override def repositories = super.repositories ++ Seq(
MavenRepository("https://oss.sonatype.org/content/repositories/snapshots"),
MavenRepository("https://oss.sonatype.org/content/repositories/releases")
)
}

object test extends Tests {
Expand Down Expand Up @@ -84,7 +89,7 @@ trait CommonRocketChip extends SbtModule with PublishModule {
override def ivyDeps = T {
Agg(
ivy"${scalaOrganization()}:scala-reflect:${scalaVersion()}",
ivy"org.json4s::json4s-jackson:3.6.6",
ivy"org.json4s::json4s-jackson:4.0.5",
ivy"org.scalatest::scalatest:3.2.0"
) ++ chisel3IvyDeps
}
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
verilator cmake ninja
python3 python3Packages.bootstrapped-pip
pkgsCross.riscv64-embedded.buildPackages.gcc
circt

spike riscvTests
];
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/amba/axis/Bundles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ case class AXISDataField(width: Int) extends BundleField(AXISData) {
}

class AXISBundleBits(val params: AXISBundleParameters) extends BundleMap(AXISBundle.keys(params)) {
override def cloneType: this.type = (new AXISBundleBits(params)).asInstanceOf[this.type]
def last = if (params.hasLast) apply(AXISLast) else true.B
def id = if (params.hasId) apply(AXISId) else 0.U
def dest = if (params.hasDest) apply(AXISDest) else 0.U
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/diplomacy/CloneModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ class ClonePorts protected[shim](elts: Data*) extends Record
{
val elements = ListMap(elts.map(d => d.instanceName -> d.chiselCloneType): _*)
def apply(field: String) = elements(field)
override def cloneType = (new ClonePorts(elts: _*)).asInstanceOf[this.type]
}
2 changes: 0 additions & 2 deletions src/main/scala/diplomacy/LazyModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ final class AutoBundle(elts: (String, Data, Boolean)*) extends Record {
val element = if (flip) data.cloneType.flip() else data.cloneType
(regex.replaceAllIn(key, ""), element, i)
}

override def cloneType: this.type = new AutoBundle(elts: _*).asInstanceOf[this.type]
}

trait ModuleValue[T] {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/diplomacy/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package freechips.rocketchip

import chisel3.internal.sourceinfo.{SourceInfo, SourceLine}
import chisel3.experimental.{SourceInfo, SourceLine}
import chisel3.Data
import org.chipsalliance.cde.config.Parameters
import scala.language.implicitConversions
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/formal/FormalUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package freechips.rocketchip.formal

import chisel3._
import chisel3.util._
import chisel3.internal.sourceinfo.{SourceInfo, SourceLine}
import org.chipsalliance.cde.config.Field
import chisel3.experimental.{SourceInfo, SourceLine}

sealed abstract class MonitorDirection(name: String) {
override def toString: String = name
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/tilelink/Bundle_ACancel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class TLBundle_ACancel(val params: TLBundleParameters) extends Record
val d = Flipped(Decoupled(new TLBundleD(params)))
val e = Decoupled(new TLBundleE(params))

override def cloneType: this.type = (new TLBundle_ACancel(params)).asInstanceOf[this.type]
val elements = ListMap("e" -> e, "d" -> d, "c" -> c, "b" -> b, "a" -> a)

/** Down-converts a TLBundle_ACancel to a plain TLBundle, dropping early/late timing split. */
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/tilelink/Bundles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ class TLBundle(val params: TLBundleParameters) extends Record
def d: DecoupledIO[TLBundleD] = optD.getOrElse(WireDefault(0.U.asTypeOf(Decoupled(new TLBundleD(params)))))
def e: DecoupledIO[TLBundleE] = optE.getOrElse(WireDefault(0.U.asTypeOf(Decoupled(new TLBundleE(params)))))

override def cloneType: this.type = (new TLBundle(params)).asInstanceOf[this.type]
val elements =
if (params.hasBCE) ListMap("e" -> e, "d" -> d, "c" -> c, "b" -> b, "a" -> a)
else ListMap("d" -> d, "a" -> a)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/tilelink/Monitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package freechips.rocketchip.tilelink

import chisel3._
import chisel3.util._
import chisel3.internal.sourceinfo.SourceLine
import org.chipsalliance.cde.config.Parameters
import chisel3.experimental.SourceLine
import freechips.rocketchip.diplomacy._
import freechips.rocketchip.util.PlusArg
import freechips.rocketchip.formal._
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/util/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import freechips.rocketchip.diplomacy._
import freechips.rocketchip.regmapper._

import org.json4s.JsonDSL._
import org.json4s.jackson.JsonMethods.{pretty, render}
import org.json4s.native.JsonMethods.{pretty, render}

/** Record a sram. */
case class SRAMAnnotation(target: Named,
Expand Down
12 changes: 0 additions & 12 deletions src/main/scala/util/BundleMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,11 @@ abstract class DataKey [T <: Data](name: String) extends BundleKey[T](name) wi
* Generally, this categorization belongs in different BundleMaps
*/

// If you extend this class, you must either redefine cloneType or have a fields constructor
class BundleMap(val fields: Seq[BundleFieldBase]) extends Record with CustomBulkAssignable {
// All fields must have distinct key.names
require(fields.map(_.key.name).distinct.size == fields.size)

val elements: ListMap[String, Data] = ListMap(fields.map { bf => bf.key.name -> chisel3.experimental.DataMirror.internal.chiselTypeClone(bf.data) } :_*)
override def cloneType: this.type = {
try {
this.getClass.getConstructors.head.newInstance(fields).asInstanceOf[this.type]
} catch {
case e: java.lang.IllegalArgumentException =>
throw new Exception("Unable to use BundleMap.cloneType on " +
this.getClass + ", probably because " + this.getClass +
" does not have a constructor accepting BundleFields. Consider overriding " +
"cloneType() on " + this.getClass, e)
}
}

// A BundleMap is best viewed as a map from BundleKey to Data
def keydata: Seq[(BundleKeyBase, Data)] = (fields zip elements) map { case (field, (_, data)) => (field.key, data) }
Expand Down
15 changes: 9 additions & 6 deletions src/main/scala/util/HeterogeneousBag.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

package freechips.rocketchip.util

import Chisel._
import chisel3.Record
import scala.collection.immutable.ListMap
import chisel3._
import chisel3.experimental.DataMirror
import scala.collection.immutable.VectorMap

final case class HeterogeneousBag[T <: Data](elts: Seq[T]) extends Record with collection.IndexedSeq[T] {
def apply(x: Int) = elts(x)
val elements = VectorMap(elts.zipWithIndex.map { case (n,i) => (i.toString, DataMirror.internal.chiselTypeClone(n)) }:_*)

def apply(x: Int): T = {
val key = elements.keys(x) // VectorMap.keys returns a Vector
elements(key)
}
def length = elts.length

override def className: String = super.className
val elements = ListMap(elts.zipWithIndex.map { case (n,i) => (i.toString, n) }:_*)
override def cloneType: this.type = (new HeterogeneousBag(elts.map(_.chiselCloneType))).asInstanceOf[this.type]
// IndexedSeq has its own hashCode/equals that we must not use
override def hashCode: Int = super[Record].hashCode
override def equals(that: Any): Boolean = super[Record].equals(that)
Expand Down
2 changes: 0 additions & 2 deletions src/main/scala/util/RecordMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ final class RecordMap[T <: Data] (eltMap: ListMap[String, T])
def size = elements.size
def data = elements.values

override def cloneType: this.type = (new RecordMap(eltMap)).asInstanceOf[this.type]

}

object RecordMap {
Expand Down

0 comments on commit d78198c

Please sign in to comment.