summaryrefslogtreecommitdiff
path: root/chiselFrontend/src/main/scala/chisel3
diff options
context:
space:
mode:
authorRichard Lin2018-10-03 16:15:37 -0700
committerGitHub2018-10-03 16:15:37 -0700
commitdafdeab614a5106dac4d80e147fdbc2770053e1b (patch)
treeefd4ae2f9b612e55c87227851813afb6644ddd3a /chiselFrontend/src/main/scala/chisel3
parentb87e6cf65920832c5a0d908b9862edcccf5cae5d (diff)
Add DataMirror.modulePorts (#901)
Diffstat (limited to 'chiselFrontend/src/main/scala/chisel3')
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala3
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Data.scala4
-rw-r--r--chiselFrontend/src/main/scala/chisel3/core/Module.scala16
3 files changed, 22 insertions, 1 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala b/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala
index 3e7251c5..57acd7b3 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/BlackBox.scala
@@ -140,7 +140,8 @@ abstract class BlackBox(val params: Map[String, Param] = Map.empty[String, Param
require(!_closed, "Can't generate module more than once")
_closed = true
- val namedPorts = io.elements.toSeq
+ val namedPorts = io.elements.toSeq.reverse // ListMaps are stored in reverse order
+
// setRef is not called on the actual io.
// There is a risk of user improperly attempting to connect directly with io
// Long term solution will be to define BlackBox IO differently as part of
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Data.scala b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
index cab6075e..869e22fb 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Data.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Data.scala
@@ -87,6 +87,10 @@ object DataMirror {
target.direction
}
+ // TODO: maybe move to something like Driver or DriverUtils, since this is mainly for interacting
+ // with compiled artifacts (vs. elaboration-time reflection)?
+ def modulePorts(target: BaseModule): Seq[(String, Data)] = target.getChiselPorts
+
// Internal reflection-style APIs, subject to change and removal whenever.
object internal {
def isSynthesizable(target: Data) = target.topBindingOpt.isDefined
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Module.scala b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
index 399f0462..88013bae 100644
--- a/chiselFrontend/src/main/scala/chisel3/core/Module.scala
+++ b/chiselFrontend/src/main/scala/chisel3/core/Module.scala
@@ -187,6 +187,22 @@ abstract class BaseModule extends HasId {
*/
final def toNamed: ModuleName = ModuleName(this.name, CircuitName(this.circuitName))
+ /**
+ * Internal API. Returns a list of this module's generated top-level ports as a map of a String
+ * (FIRRTL name) to the IO object. Only valid after the module is closed.
+ *
+ * Note: for BlackBoxes (but not ExtModules), this returns the contents of the top-level io
+ * object, consistent with what is emitted in FIRRTL.
+ *
+ * TODO: Use SeqMap/VectorMap when those data structures become available.
+ */
+ private[core] def getChiselPorts: Seq[(String, Data)] = {
+ require(_closed, "Can't get ports before module close")
+ _component.get.ports.map { port =>
+ (port.id.getRef.asInstanceOf[ModuleIO].name, port.id)
+ }
+ }
+
/** Called at the Module.apply(...) level after this Module has finished elaborating.
* Returns a map of nodes -> names, for named nodes.
*