-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for optional groups. These are groups of statements with optional functionality. The primary use case is intended for verification code to "extract" such code into bound modules. Signed-off-by: Schuyler Eldridge <schuyler.eldridge@sifive.com>
- Loading branch information
Showing
7 changed files
with
244 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package chisel3 | ||
|
||
import chisel3.internal.{Builder, HasId} | ||
import chisel3.internal.firrtl.{GroupDefBegin, GroupDefEnd, Node} | ||
import chisel3.experimental.SourceInfo | ||
import scala.collection.mutable.LinkedHashSet | ||
|
||
object group { | ||
|
||
object Convention { | ||
sealed trait Type | ||
private[chisel3] case object Root extends Type | ||
case object Bind extends Type | ||
} | ||
|
||
// TODO: All this mutable state needs to be cleaned up and moved into the | ||
// Builder. The naming needs to be handled more inteligently. | ||
abstract class Declaration(val convention: Convention.Type)(implicit _parent: Declaration) { self: Singleton => | ||
protected implicit val thiz: Declaration = self | ||
|
||
private[chisel3] def parent: Declaration = _parent | ||
|
||
private[chisel3] def name: String = Utils.goodName(this) | ||
} | ||
|
||
object Declaration { | ||
case object Root extends Declaration(Convention.Root)(null) | ||
implicit val rootDeclaration: Declaration = Root | ||
} | ||
|
||
/** Add a declaration and all of its parents to the Builder. This lets the | ||
* Builder know that this group was used and should be emitted in the FIRRTL. | ||
*/ | ||
private[chisel3] def addDeclarations(declaration: Declaration) = { | ||
var currentDeclaration: Declaration = declaration | ||
while (currentDeclaration != Declaration.Root && !Builder.groups.contains(currentDeclaration)) { | ||
val decl = currentDeclaration | ||
val parent = decl.parent | ||
|
||
Builder.groups += decl | ||
currentDeclaration = parent | ||
} | ||
} | ||
|
||
def apply[A]( | ||
declaration: Declaration | ||
)(block: => A | ||
)( | ||
implicit sourceInfo: SourceInfo | ||
): Unit = { | ||
Builder.pushCommand(GroupDefBegin(sourceInfo, declaration)) | ||
addDeclarations(declaration) | ||
Builder.groupStack = declaration :: Builder.groupStack | ||
block | ||
Builder.pushCommand(GroupDefEnd(sourceInfo)) | ||
Builder.groupStack = Builder.groupStack.tail | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.