forked from chipsalliance/chisel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sc
268 lines (198 loc) · 7.18 KB
/
common.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import mill._
import mill.scalalib._
trait HasMacroAnnotations
extends ScalaModule {
override def scalacOptions = T {
super.scalacOptions() ++ Agg("-Ymacro-annotations")
}
}
trait MacrosModule
extends ScalaModule
with HasMacroAnnotations {
def scalaReflectIvy: Dep
override def ivyDeps = super.ivyDeps() ++ Some(scalaReflectIvy)
}
trait FirrtlModule
extends ScalaModule
with HasMacroAnnotations {
def osLibModuleIvy: Dep
def json4sIvy: Dep
def dataclassIvy: Dep
def commonTextIvy: Dep
def scoptIvy: Dep
override def ivyDeps = super.ivyDeps() ++ Agg(
osLibModuleIvy,
json4sIvy,
dataclassIvy,
commonTextIvy,
scoptIvy
)
}
trait SvsimModule
extends ScalaModule {
}
trait CoreModule
extends ScalaModule
with HasMacroAnnotations {
def firrtlModule: FirrtlModule
def macrosModule: MacrosModule
def osLibModuleIvy: Dep
def upickleModuleIvy: Dep
def firtoolResolverModuleIvy: Dep
override def moduleDeps = super.moduleDeps ++ Seq(macrosModule, firrtlModule)
override def ivyDeps = super.ivyDeps() ++ Agg(
osLibModuleIvy,
upickleModuleIvy,
firtoolResolverModuleIvy
)
}
trait PluginModule
extends ScalaModule {
def scalaLibraryIvy: Dep
def scalaReflectIvy: Dep
def scalaCompilerIvy: Dep
override def ivyDeps = super.ivyDeps() ++ Agg(scalaLibraryIvy, scalaReflectIvy, scalaCompilerIvy)
}
trait HasChiselPlugin
extends ScalaModule {
def pluginModule: PluginModule
override def scalacOptions = T {
super.scalacOptions() ++ Agg(s"-Xplugin:${pluginModule.jar().path}")
}
override def scalacPluginClasspath = T {
super.scalacPluginClasspath() ++ Agg(
pluginModule.jar()
)
}
}
trait StdLibModule
extends ScalaModule
with HasChisel
trait ChiselModule
extends ScalaModule
with HasChiselPlugin
with HasMacroAnnotations {
def macrosModule: MacrosModule
def svsimModule: SvsimModule
def coreModule: CoreModule
override def scalacPluginClasspath = T(super.scalacPluginClasspath() ++ Agg(pluginModule.jar()))
override def moduleDeps = super.moduleDeps ++ Seq(macrosModule, coreModule, svsimModule)
}
trait HasChisel
extends ScalaModule
with HasChiselPlugin {
def chiselModule: ChiselModule
override def moduleDeps = super.moduleDeps ++ Some(chiselModule)
}
trait HasJextractGeneratedSources
extends JavaModule {
def includePaths: T[Seq[PathRef]]
def libraryPaths: T[Seq[PathRef]]
def header: T[PathRef]
def includeFunctions: T[Seq[String]]
def includeConstants: T[Seq[String]]
def includeStructs: T[Seq[String]]
def includeTypedefs: T[Seq[String]]
def includeUnions: T[Seq[String]]
def includeVars: T[Seq[String]]
def linkLibraries: T[Seq[String]]
def target: T[String]
def headerClassName: T[String]
def dumpAllIncludes = T {
val f = os.temp()
os.proc(
Seq("jextract", header().path.toString)
++ includePaths().flatMap(p => Seq("-I", p.path.toString))
++ Seq("--dump-includes", f.toString)
).call()
os.read.lines(f).filter(s => s.nonEmpty && !s.startsWith("#"))
}
override def generatedSources: T[Seq[PathRef]] = T {
super.generatedSources() ++ {
// @formatter:off
os.proc(
Seq("jextract", header().path.toString)
++ includePaths().flatMap(p => Seq("-I", p.path.toString))
++ Seq(
"-t", target(),
"--header-class-name", headerClassName(),
"--source",
"--output", T.dest.toString
) ++ includeFunctions().flatMap(f => Seq("--include-function", f)) ++
includeConstants().flatMap(f => Seq("--include-constant", f)) ++
includeStructs().flatMap(f => Seq("--include-struct", f)) ++
includeTypedefs().flatMap(f => Seq("--include-typedef", f)) ++
includeUnions().flatMap(f => Seq("--include-union", f)) ++
includeVars().flatMap(f => Seq("--include-var", f)) ++
linkLibraries().flatMap(l => Seq("-l", l))
).call(T.dest)
// @formatter:on
Lib
.findSourceFiles(os.walk(T.dest).map(PathRef(_)), Seq("java"))
.distinct
.map(PathRef(_))
}
}
override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
}
// Java Codegen for all declared functions.
// All of these functions are not private API which is subject to change.
trait CIRCTPanamaBindingModule
extends HasJextractGeneratedSources {
def includeConstants = T.input(os.read.lines(millSourcePath / "includeConstants.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def includeFunctions = T.input(os.read.lines(millSourcePath / "includeFunctions.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def includeStructs = T.input(os.read.lines(millSourcePath / "includeStructs.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def includeTypedefs = T.input(os.read.lines(millSourcePath / "includeTypedefs.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def includeUnions = T.input(os.read.lines(millSourcePath / "includeUnions.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def includeVars = T.input(os.read.lines(millSourcePath / "includeVars.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def linkLibraries = T.input(os.read.lines(millSourcePath / "linkLibraries.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def target = T("org.llvm.circt")
def headerClassName = T("CAPI")
}
trait HasCIRCTPanamaBindingModule
extends JavaModule {
def circtPanamaBindingModule: CIRCTPanamaBindingModule
override def moduleDeps = super.moduleDeps ++ Some(circtPanamaBindingModule)
override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
override def forkArgs: T[Seq[String]] = T(
super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview")
++ circtPanamaBindingModule
.libraryPaths()
.map(p => s"-Djava.library.path=${p.path}")
)
}
// The Scala API for PanamaBinding, API here is experimentally public to all developers
trait PanamaLibModule
extends ScalaModule
with HasCIRCTPanamaBindingModule
trait HasPanamaLibModule
extends ScalaModule
with HasCIRCTPanamaBindingModule {
def panamaLibModule: PanamaLibModule
def circtPanamaBindingModule = panamaLibModule.circtPanamaBindingModule
override def moduleDeps = super.moduleDeps ++ Some(panamaLibModule)
}
trait PanamaOMModule
extends ScalaModule
with HasPanamaLibModule
trait HasPanamaOMModule
extends ScalaModule
with HasCIRCTPanamaBindingModule {
def panamaOMModule: PanamaOMModule
def circtPanamaBindingModule = panamaOMModule.circtPanamaBindingModule
override def moduleDeps = super.moduleDeps ++ Some(panamaOMModule)
}
trait PanamaConverterModule
extends ScalaModule
with HasPanamaOMModule
with HasChisel
trait HasPanamaConverterModule
extends ScalaModule
with HasCIRCTPanamaBindingModule
with HasChisel {
def panamaConverterModule: PanamaConverterModule
def circtPanamaBindingModule = panamaConverterModule.circtPanamaBindingModule
override def chiselModule = panamaConverterModule.chiselModule
override def pluginModule = panamaConverterModule.pluginModule
override def moduleDeps = super.moduleDeps ++ Some(panamaConverterModule)
}