summaryrefslogtreecommitdiff
path: root/src/main/scala/chisel3/util/TransitName.scala
diff options
context:
space:
mode:
authorJim Lawson2016-07-19 13:43:48 -0700
committerJim Lawson2016-07-19 13:43:48 -0700
commitb27f29902d9f1d886e8edf1fc5e960cf9a634184 (patch)
treec6f3e27e46e5ed9c3cc62f2c368c766cdded74c6 /src/main/scala/chisel3/util/TransitName.scala
parent083610b2faa456dfccc4365dd115565d36e522fa (diff)
parent12810b5efe6a8f872fbc1c63cdfb835ca354624f (diff)
Merge branch 'sdtwigg_rebase_renamechisel3' into sdtwigg_wrap_renamechisel3
Diffstat (limited to 'src/main/scala/chisel3/util/TransitName.scala')
-rw-r--r--src/main/scala/chisel3/util/TransitName.scala22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/scala/chisel3/util/TransitName.scala b/src/main/scala/chisel3/util/TransitName.scala
new file mode 100644
index 00000000..f36f926f
--- /dev/null
+++ b/src/main/scala/chisel3/util/TransitName.scala
@@ -0,0 +1,22 @@
+package chisel3.util
+
+import chisel3._
+import internal.HasId
+
+object TransitName {
+ // The purpose of this is to allow a library to 'move' a name call to a more
+ // appropriate place.
+ // For example, a library factory function may create a module and return
+ // the io. The only user-exposed field is that given IO, which can't use
+ // any name supplied by the user. This can add a hook so that the supplied
+ // name then names the Module.
+ // See Queue companion object for working example
+ def apply[T<:HasId](from: T, to: HasId): T = {
+ from.addPostnameHook((given_name: String) => {to.suggestName(given_name)})
+ from
+ }
+ def withSuffix[T<:HasId](suffix: String)(from: T, to: HasId): T = {
+ from.addPostnameHook((given_name: String) => {to.suggestName(given_name+suffix)})
+ from
+ }
+}