1/*************************************************************************************** 2* Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences 3* Copyright (c) 2020-2021 Peng Cheng Laboratory 4* 5* XiangShan is licensed under Mulan PSL v2. 6* You can use this software according to the terms and conditions of the Mulan PSL v2. 7* You may obtain a copy of Mulan PSL v2 at: 8* http://license.coscl.org.cn/MulanPSL2 9* 10* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13* 14* See the Mulan PSL v2 for more details. 15***************************************************************************************/ 16 17import mill._ 18import scalalib._ 19import $file.`rocket-chip`.common 20import $file.`rocket-chip`.cde.common 21import $file.`rocket-chip`.hardfloat.build 22import $file.huancun.common 23import $file.coupledL2.common 24 25val defaultScalaVersion = "2.13.10" 26 27def defaultVersions(chiselVersion: String) = chiselVersion match { 28 case "chisel" => Map( 29 "chisel" -> ivy"org.chipsalliance::chisel:6.0.0-RC1", 30 "chisel-plugin" -> ivy"org.chipsalliance:::chisel-plugin:6.0.0-RC1", 31 "chiseltest" -> ivy"edu.berkeley.cs::chiseltest:5.0.2" 32 ) 33 case "chisel3" => Map( 34 "chisel" -> ivy"edu.berkeley.cs::chisel3:3.6.0", 35 "chisel-plugin" -> ivy"edu.berkeley.cs:::chisel3-plugin:3.6.0", 36 "chiseltest" -> ivy"edu.berkeley.cs::chiseltest:0.6.2" 37 ) 38} 39 40trait HasChisel extends SbtModule with Cross.Module[String] { 41 def chiselModule: Option[ScalaModule] = None 42 43 def chiselPluginJar: T[Option[PathRef]] = None 44 45 def chiselIvy: Option[Dep] = Some(defaultVersions(crossValue)("chisel")) 46 47 def chiselPluginIvy: Option[Dep] = Some(defaultVersions(crossValue)("chisel-plugin")) 48 49 override def scalaVersion = defaultScalaVersion 50 51 override def scalacOptions = super.scalacOptions() ++ 52 Agg("-language:reflectiveCalls", "-Ymacro-annotations", "-Ytasty-reader") 53 54 override def ivyDeps = super.ivyDeps() ++ Agg(chiselIvy.get) 55 56 override def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ Agg(chiselPluginIvy.get) 57} 58 59object rocketchip extends Cross[RocketChip]("chisel", "chisel3") 60 61trait RocketChip 62 extends millbuild.`rocket-chip`.common.RocketChipModule 63 with HasChisel { 64 def scalaVersion: T[String] = T(defaultScalaVersion) 65 66 override def millSourcePath = os.pwd / "rocket-chip" 67 68 def macrosModule = macros 69 70 def hardfloatModule = hardfloat(crossValue) 71 72 def cdeModule = cde 73 74 def mainargsIvy = ivy"com.lihaoyi::mainargs:0.5.4" 75 76 def json4sJacksonIvy = ivy"org.json4s::json4s-jackson:4.0.6" 77 78 object macros extends Macros 79 80 trait Macros 81 extends millbuild.`rocket-chip`.common.MacrosModule 82 with SbtModule { 83 84 def scalaVersion: T[String] = T(defaultScalaVersion) 85 86 def scalaReflectIvy = ivy"org.scala-lang:scala-reflect:${defaultScalaVersion}" 87 } 88 89 object hardfloat extends Cross[Hardfloat](crossValue) 90 91 trait Hardfloat 92 extends millbuild.`rocket-chip`.hardfloat.common.HardfloatModule with HasChisel { 93 94 def scalaVersion: T[String] = T(defaultScalaVersion) 95 96 override def millSourcePath = os.pwd / "rocket-chip" / "hardfloat" / "hardfloat" 97 98 } 99 100 object cde extends CDE 101 102 trait CDE extends millbuild.`rocket-chip`.cde.common.CDEModule with ScalaModule { 103 104 def scalaVersion: T[String] = T(defaultScalaVersion) 105 106 override def millSourcePath = os.pwd / "rocket-chip" / "cde" / "cde" 107 } 108} 109 110object utility extends Cross[Utility]("chisel", "chisel3") 111trait Utility extends HasChisel { 112 113 override def millSourcePath = os.pwd / "utility" 114 115 override def moduleDeps = super.moduleDeps ++ Seq( 116 rocketchip(crossValue) 117 ) 118 119} 120 121object huancun extends Cross[HuanCun]("chisel", "chisel3") 122trait HuanCun extends millbuild.huancun.common.HuanCunModule with HasChisel { 123 124 override def millSourcePath = os.pwd / "huancun" 125 126 def rocketModule: ScalaModule = rocketchip(crossValue) 127 128 def utilityModule: ScalaModule = utility(crossValue) 129 130} 131 132object coupledL2 extends Cross[CoupledL2]("chisel", "chisel3") 133trait CoupledL2 extends millbuild.coupledL2.common.CoupledL2Module with HasChisel { 134 135 override def millSourcePath = os.pwd / "coupledL2" 136 137 def rocketModule: ScalaModule = rocketchip(crossValue) 138 139 def utilityModule: ScalaModule = utility(crossValue) 140 141 def huancunModule: ScalaModule = huancun(crossValue) 142 143} 144 145object difftest extends Cross[Difftest]("chisel", "chisel3") 146trait Difftest extends HasChisel { 147 148 override def millSourcePath = os.pwd / "difftest" 149 150} 151 152object fudian extends Cross[FuDian]("chisel", "chisel3") 153trait FuDian extends HasChisel { 154 155 override def millSourcePath = os.pwd / "fudian" 156 157} 158 159// extends this trait to use XiangShan in other projects 160trait XiangShanModule extends ScalaModule { 161 162 def rocketModule: ScalaModule 163 164 def difftestModule: ScalaModule 165 166 def huancunModule: ScalaModule 167 168 def coupledL2Module: ScalaModule 169 170 def fudianModule: ScalaModule 171 172 def utilityModule: ScalaModule 173 174 override def moduleDeps = super.moduleDeps ++ Seq( 175 rocketModule, 176 difftestModule, 177 huancunModule, 178 coupledL2Module, 179 fudianModule, 180 utilityModule, 181 ) 182 183} 184 185object xiangshan extends Cross[XiangShan]("chisel", "chisel3") 186trait XiangShan extends XiangShanModule with HasChisel { 187 188 override def millSourcePath = os.pwd 189 190 def rocketModule = rocketchip(crossValue) 191 192 def difftestModule = difftest(crossValue) 193 194 def huancunModule = huancun(crossValue) 195 196 def coupledL2Module = coupledL2(crossValue) 197 198 def fudianModule = fudian(crossValue) 199 200 def utilityModule = utility(crossValue) 201 202 override def forkArgs = Seq("-Xmx20G", "-Xss256m") 203 204 override def sources = T.sources { 205 super.sources() ++ Seq(PathRef(millSourcePath / "src" / crossValue / "main" / "scala")) 206 } 207 208 object test extends SbtModuleTests with TestModule.ScalaTest { 209 override def forkArgs = Seq("-Xmx20G", "-Xss256m") 210 211 override def sources = T.sources { 212 super.sources() ++ Seq(PathRef(millSourcePath / "src" / crossValue / "test" / "scala")) 213 } 214 215 override def ivyDeps = super.ivyDeps() ++ Agg( 216 defaultVersions(crossValue)("chiseltest") 217 ) 218 } 219} 220