Skip to content

Commit 2c15a6f

Browse files
committed
[core] Add layer ABis
Add an enumeration and functions that can be used to help generate the information for the two standard layer convention ABIs. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent d7d6f53 commit 2c15a6f

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

core/src/main/scala/chisel3/Layer.scala

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,56 @@ object layer {
2727
final case object Bind extends Type
2828
}
2929

30+
/** Enumeration of different application binary interfaces (ABIs) for how to
31+
* enable layers. These are implementations of the FIRRTL ABI Specification.
32+
*/
33+
object ABI {
34+
sealed trait Type
35+
36+
/** An ABI that is implemented as a file included during Verilog elabortion. */
37+
final case object FileInclude extends Type {
38+
39+
/** Retun the file name of
40+
*/
41+
def toFilename(layer: Layer, circuitName: String): String = {
42+
(s"layers-$circuitName" +: layer.layerSeq.map(_.name)).mkString("-") + ".sv"
43+
}
44+
45+
}
46+
47+
/** An ABI that requires a preprocessor macro identifier to be defined during Verilog elaboration.
48+
*/
49+
final case object PreprocessorDefine extends Type {
50+
51+
/** Return the macro identifier that should be defined. */
52+
def toMacroIdentifier(layer: Layer, circuitName: String): String = {
53+
(s"layer_$circuitName" +: layer.layerSeq.map(_.name)).mkString("$")
54+
}
55+
56+
}
57+
58+
/** A dummy ABI for the root LayerConfig. This should be unused otherwise. */
59+
final case object Root extends Type
60+
}
61+
3062
sealed trait OutputDirBehavior
3163
final case object DefaultOutputDir extends OutputDirBehavior
3264
final case object NoOutputDir extends OutputDirBehavior
3365
final case class CustomOutputDir(path: Path) extends OutputDirBehavior
3466

35-
sealed trait LayerConfig
67+
sealed trait LayerConfig {
68+
def abi: ABI.Type
69+
}
3670
object LayerConfig {
37-
final case class Extract(outputDirBehavior: OutputDirBehavior = DefaultOutputDir) extends LayerConfig
38-
final case object Inline extends LayerConfig
39-
private[chisel3] final case object Root extends LayerConfig
71+
final case class Extract(outputDirBehavior: OutputDirBehavior = DefaultOutputDir) extends LayerConfig {
72+
override val abi: ABI.Type = ABI.FileInclude
73+
}
74+
final case object Inline extends LayerConfig {
75+
override val abi: ABI.Type = ABI.PreprocessorDefine
76+
}
77+
private[chisel3] final case object Root extends LayerConfig {
78+
override val abi: ABI.Type = ABI.Root
79+
}
4080
}
4181

4282
/** A layer declaration.

0 commit comments

Comments
 (0)