Skip to content

Commit d7d6f53

Browse files
committed
[core] Add private Layer.layerSeq member function
Add a function that returns that sequence of all layers from the current layer up to the root. This is part of forthcoming support for different layer convention ABIs which need to use this information in their ABI utility functions. Signed-off-by: Schuyler Eldridge <[email protected]>
1 parent ba19b6d commit d7d6f53

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import chisel3.internal.firrtl.ir.{LayerBlock, Node}
88
import chisel3.util.simpleClassName
99
import java.nio.file.{Path, Paths}
1010
import scala.annotation.tailrec
11-
import scala.collection.mutable.LinkedHashSet
11+
import scala.collection.mutable.{ArrayBuffer, LinkedHashSet}
1212

1313
/** This object contains Chisel language features for creating layers. Layers
1414
* are collections of hardware that are not always present in the circuit.
@@ -120,6 +120,19 @@ object layer {
120120
case _ if this == that => true
121121
case _ => this.canWriteTo(that.parent)
122122
}
123+
124+
/** Return a list containg this layer and all its parents, excluding the root
125+
* layer. The deepest layer (this layer) is the first element in the list.
126+
*
127+
* @return a sequence of all layers
128+
*/
129+
private[chisel3] def layerSeq: List[Layer] = {
130+
def rec(current: Layer, acc: List[Layer]): List[Layer] = current match {
131+
case Layer.root => acc
132+
case _ => rec(current.parent, current :: acc)
133+
}
134+
rec(this, Nil)
135+
}
123136
}
124137

125138
object Layer {

0 commit comments

Comments
 (0)