-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sc
229 lines (169 loc) · 7.29 KB
/
build.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import mill._
import scalalib._
import $file.`chisel`.`rocket-chip`.common
import $file.`chisel`.`rocket-chip`.cde.common
import $file.`chisel`.`rocket-chip`.hardfloat.build
val spinalVersion = "1.9.4"
def relatedScalaVersion = "2.13.10"
def chiselScalaVersion = "2.13.10"
def spinalhdlScalaVersion = "2.11.12"
val defaultSpinalhdlVersions = Map(
"spinalCore" -> ivy"com.github.spinalhdl::spinalhdl-core:$spinalVersion",
"spinalLib" -> ivy"com.github.spinalhdl::spinalhdl-lib:$spinalVersion",
"spinalPlugin" -> ivy"com.github.spinalhdl::spinalhdl-idsl-plugin:$spinalVersion",
"scalatest" -> ivy"org.scalatest::scalatest:3.2.2",
"macroParadise" -> ivy"org.scalamacros:::paradise:2.1.1",
"yaml" -> ivy"org.yaml:snakeyaml:1.8"
)
def defaultChiselVersions(chiselVersion: String) = chiselVersion match {
case "chisel" => Map(
"chisel" -> ivy"org.chipsalliance::chisel:6.0.0-RC1",
"chisel-plugin" -> ivy"org.chipsalliance:::chisel-plugin:6.0.0-RC1",
"chiseltest" -> ivy"edu.berkeley.cs::chiseltest:5.0.2",
"mainargs" -> ivy"com.lihaoyi::mainargs:0.5.0"
)
case "chisel3" => Map(
"chisel" -> ivy"edu.berkeley.cs::chisel3:3.6.0",
"chisel-plugin" -> ivy"edu.berkeley.cs:::chisel3-plugin:3.6.0",
"chiseltest" -> ivy"edu.berkeley.cs::chiseltest:0.6.2",
"mainargs" -> ivy"com.lihaoyi::mainargs:0.5.0"
)
}
trait HasSpinalhdl extends ScalaModule {
val spinalhdlDeps = Agg(defaultSpinalhdlVersions("spinalCore"),
defaultSpinalhdlVersions("spinalLib"),
defaultSpinalhdlVersions("yaml"))
val spinalhdlPluginDeps = Agg(defaultSpinalhdlVersions("macroParadise"),
defaultSpinalhdlVersions("spinalPlugin"))
override def scalaVersion = spinalhdlScalaVersion
override def scalacPluginIvyDeps = spinalhdlPluginDeps
override def ivyDeps = spinalhdlDeps
override def scalacOptions = Seq("-Xsource:2.11")
}
trait HasChisel extends SbtModule with Cross.Module[String] {
def chiselModule: Option[ScalaModule] = None
def chiselPluginJar: T[Option[PathRef]] = None
def defaultScalaVersion: String = chiselScalaVersion
def chiselIvy: Option[Dep] = Some(defaultChiselVersions(crossValue)("chisel"))
def chiselPluginIvy: Option[Dep] = Some(defaultChiselVersions(crossValue)("chisel-plugin"))
def changbaiMainargsIvy : Option[Dep] = Some(defaultChiselVersions(crossValue)("mainargs"))
override def scalaVersion = defaultScalaVersion
override def scalacOptions = super.scalacOptions() ++
Agg("-language:reflectiveCalls", "-Ymacro-annotations", "-Ytasty-reader")
val compileDeps = Agg(changbaiMainargsIvy.get)
val chiselDeps = Agg(chiselIvy.get)
val chiselPluginDeps = Agg(chiselPluginIvy.get)
override def ivyDeps = super.ivyDeps() ++ chiselDeps ++ compileDeps
override def scalacPluginIvyDeps = super.scalacPluginIvyDeps() ++ chiselPluginDeps
}
object rocketchip extends Cross[RocketChip]("chisel", "chisel3")
trait RocketChip
extends millbuild.`chisel`.`rocket-chip`.common.RocketChipModule
with HasChisel {
def scalaVersion: T[String] = T(defaultScalaVersion)
override def millSourcePath = os.pwd / "chisel" /"rocket-chip"
def macrosModule = macros
def hardfloatModule = hardfloat(crossValue)
def cdeModule = cde
def mainargsIvy = ivy"com.lihaoyi::mainargs:0.5.4"
def json4sJacksonIvy = ivy"org.json4s::json4s-jackson:4.0.6"
object macros extends Macros
trait Macros
extends millbuild.`chisel`.`rocket-chip`.common.MacrosModule
with SbtModule {
def scalaVersion: T[String] = T(defaultScalaVersion)
def scalaReflectIvy = ivy"org.scala-lang:scala-reflect:${defaultScalaVersion}"
}
object hardfloat extends Cross[Hardfloat](crossValue)
trait Hardfloat
extends millbuild.`chisel`.`rocket-chip`.hardfloat.common.HardfloatModule with HasChisel {
def scalaVersion: T[String] = T(defaultScalaVersion)
override def millSourcePath = os.pwd / "chisel" /"rocket-chip" / "hardfloat" / "hardfloat"
}
object cde extends CDE
trait CDE extends millbuild.`chisel`.`rocket-chip`.cde.common.CDEModule with ScalaModule {
def scalaVersion: T[String] = T(defaultScalaVersion)
override def millSourcePath = os.pwd / "chisel" / "rocket-chip" / "cde" / "cde"
}
}
object vexriscv extends HasSpinalhdl with SbtModule{
override def millSourcePath = os.pwd / "spinal" / "VexRiscv"
override def moduleDeps: Seq[JavaModule] = super.moduleDeps
}
class Changbai(chiselGenerator: String = "SimpleGenerator") extends Module{
object chisel extends Cross[ChiselModules]("chisel", "chisel3")
trait ChiselModules extends HasChisel with SbtModule {
def chiselPluginJar: T[Option[PathRef]]
override def scalacOptions = T(super.scalacOptions() ++ chiselPluginJar().map(path => s"-Xplugin:${path.path}"))
override def millSourcePath = os.pwd / "chisel"
override def mainClass = T(Some(s"generators.${chiselGenerator}"))
def rocketModule = rocketchip(crossValue)
override def moduleDeps: Seq[JavaModule] = super.moduleDeps ++ Seq(rocketModule)
}
object spinal extends HasSpinalhdl with SbtModule{
override def millSourcePath = os.pwd / "spinal"
def vexriscvModule = vexriscv
object test extends SbtModuleTests with TestModule.ScalaTest
override def moduleDeps: Seq[JavaModule] = super.moduleDeps ++ Seq(vexriscvModule)
}
}
object changbaiV1 extends Changbai
trait Emulator extends Cross.Module3[String, String, String] {
val top: String = crossValue
val config: String = crossValue2
val chiselGenerator: String = crossValue3
val cb = new Changbai(chiselGenerator)
object generator extends Module {
def elaborate = T {
os.proc(
mill.util.Jvm.javaExe,
"-jar",
cb.chisel("chisel").assembly().path,
"--dir", T.dest.toString,
"--top", top,
"--config", config,
).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
}
}
object mfccompiler extends Module {
def compile = T {
println(generator.chirrtl().path)
println(generator.chiselAnno().path)
println(T.dest)
os.proc("firtool",
generator.chirrtl().path,
s"--annotation-file=${generator.chiselAnno().path}",
"--disable-annotation-unknown",
"--disable-all-randomization",
"-O=debug",
"--split-verilog",
"--preserve-values=named",
"--output-annotation-file=mfc.anno.json",
s"-o=${T.dest}"
).call(T.dest)
PathRef(T.dest)
}
// here is build chain
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 emulator extends Cross[Emulator](
("sandbox.Hello", "sandbox.HelloConfig", "DiplomacyGenerator"),
("examples.Adder", "sandbox.HelloConfig", "SimpleGenerator")
)