summaryrefslogtreecommitdiff
path: root/core/src/main/scala/chisel3/RawModule.scala
diff options
context:
space:
mode:
authorJack2022-11-11 06:53:04 +0000
committerJack2022-11-11 06:53:04 +0000
commit3ce953c81f06519351c48277e3474b5720ec07ff (patch)
treeac79dcb80d0528c2ae86ca21da4cf424715ab645 /core/src/main/scala/chisel3/RawModule.scala
parentadccde9998c91875e5490cff6d5822ffacc593ed (diff)
parentc8046636a25474be4c547c6fe9c6d742ea7b1d13 (diff)
Merge branch '3.5.x' into 3.5-release
Diffstat (limited to 'core/src/main/scala/chisel3/RawModule.scala')
-rw-r--r--core/src/main/scala/chisel3/RawModule.scala14
1 files changed, 9 insertions, 5 deletions
diff --git a/core/src/main/scala/chisel3/RawModule.scala b/core/src/main/scala/chisel3/RawModule.scala
index f2ce4c70..9668313a 100644
--- a/core/src/main/scala/chisel3/RawModule.scala
+++ b/core/src/main/scala/chisel3/RawModule.scala
@@ -2,7 +2,6 @@
package chisel3
-import scala.collection.mutable.{ArrayBuffer, HashMap}
import scala.util.Try
import scala.language.experimental.macros
import scala.annotation.nowarn
@@ -13,6 +12,7 @@ import chisel3.internal.Builder._
import chisel3.internal.firrtl._
import chisel3.internal.sourceinfo.UnlocatableSourceInfo
import _root_.firrtl.annotations.{IsModule, ModuleTarget}
+import scala.collection.immutable.VectorBuilder
/** Abstract base class for Modules that contain Chisel RTL.
* This abstract base class is a user-defined module which does not include implicit clock and reset and supports
@@ -23,14 +23,18 @@ abstract class RawModule(implicit moduleCompileOptions: CompileOptions) extends
//
// RTL construction internals
//
- private val _commands = ArrayBuffer[Command]()
+ // Perhaps this should be an ArrayBuffer (or ArrayBuilder), but DefModule is public and has Seq[Command]
+ // so our best option is to share a single Seq datastructure with that
+ private val _commands = new VectorBuilder[Command]()
private[chisel3] def addCommand(c: Command) {
require(!_closed, "Can't write to module after module close")
_commands += c
}
- protected def getCommands = {
+ protected def getCommands: Seq[Command] = {
require(_closed, "Can't get commands before module close")
- _commands.toSeq
+ // Unsafe cast but we know that any RawModule uses a DefModule
+ // _component is defined as a var on BaseModule and we cannot override mutable vars
+ _component.get.asInstanceOf[DefModule].commands
}
//
@@ -153,7 +157,7 @@ abstract class RawModule(implicit moduleCompileOptions: CompileOptions) extends
Seq()
}
}
- val component = DefModule(this, name, firrtlPorts, invalidateCommands ++ getCommands)
+ val component = DefModule(this, name, firrtlPorts, invalidateCommands ++: _commands.result())
_component = Some(component)
_component
}