From 73e35c55c7a3f4be98432fd275e0e0ae7db76d46 Mon Sep 17 00:00:00 2001 From: Stephen Twigg Date: Wed, 27 Apr 2016 16:46:23 -0700 Subject: Add HasId=Module|Data.suggestName, TransitName util Often times the scala runtime reflection fails to find an appropriate name for a given net. This commit tries to partially ameliorate the issue by exposing a suggestName function onto HasId (i.e. Module, Data) that the user can call to 'suggest' a name. Only the first suggestion is taken so repeated calls to suggestName will not change the name for that node. This type of name exposure is slightly risky as there is a chance the same name is suggested in the same namespace. Thus, naming within a Module occurs in two passes: The suggestion phase is when the user calls suggestName, etc. Near the 'end,' the Module uses runtime reflection to suggest names as well. The forcing phase is when all the nodes are run through and a name is 'forced' onto them, using the namespace to suggest alternatives if the desired one is taken. If no suggestion is present, the default name is T, as before. Second, there is an issue that commonly comes up when a component library creates intermediate logic and then only returns a piece, or even a piece of a piece (like part of a module IO). Any names suggested by the Module by reflection onto that return value are either lost or not fully applied. This issue is resolved by TransitName. TransitName attaches a hook to the suggestName function of a HasId. With that hook, any time suggestName is called on the hooked ID, that name suggestion is also applied to other nodes. For example, if Queue(in) is called, then any attempts to name the returned output DecoupledIO will actually translate to naming attempts on the backing Queue. --- src/main/scala/Chisel/Module.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/main/scala/Chisel/Module.scala') diff --git a/src/main/scala/Chisel/Module.scala b/src/main/scala/Chisel/Module.scala index 22c1f9c3..cfcf5a48 100644 --- a/src/main/scala/Chisel/Module.scala +++ b/src/main/scala/Chisel/Module.scala @@ -76,16 +76,18 @@ abstract class Module(_clock: Clock = null, _reset: Bool = null) extends HasId { for ((port, name) <- ports) port.setRef(ModuleIO(this, _namespace.name(name))) + // Suggest names to nodes using runtime reflection val valNames = HashSet[String](getClass.getDeclaredFields.map(_.getName):_*) def isPublicVal(m: java.lang.reflect.Method) = m.getParameterTypes.isEmpty && valNames.contains(m.getName) val methods = getClass.getMethods.sortWith(_.getName > _.getName) for (m <- methods; if isPublicVal(m)) m.invoke(this) match { - case id: HasId => id.setRef(_namespace.name(m.getName)) + case (id: HasId) => id.suggestName(m.getName) case _ => } - _ids.foreach(_.setRef(_namespace.name("T"))) + // All suggestions are in, force names to every node. + _ids.foreach(_.forceName(default="T", _namespace)) _ids.foreach(_._onModuleClose) this } -- cgit v1.2.3