@@ -52,12 +52,16 @@ class MapChiselToVcd[T <: RawModule](generateModule: () => T, private val workin
5252 chiselIRParser.parseCircuit(circuitChiselIR)
5353
5454 // Step 4. Parse the debug information
55- private val gDebugIRParser = new DebugIRParser (workingDir, TypedConverter .getDebugIRFile(gOpt = true ))
55+ private val topModuleName = circuitChiselIR.name
56+ private val gDebugIRParser = new DebugIRParser (workingDir, TypedConverter .getDebugIRFile(gOpt = true , topModuleName))
57+ logger.error(s " HGDD file used: ${TypedConverter .getDebugIRFile(gOpt = true , topModuleName)}" )
5658 // val debugIRParser =
5759 // new DebugIRParser(workingDir, TypedConverter.getDebugIRFile(gOpt = false)) // TODO: check if this is needed or not
5860
5961 gDebugIRParser.parse()
6062 // debugIRParser.parse()
63+ mapCircuits()
64+ dumpLog()
6165
6266 /** Print debug information */
6367 def printDebug (): Unit = {
@@ -187,21 +191,25 @@ class MapChiselToVcd[T <: RawModule](generateModule: () => T, private val workin
187191
188192 // Each element is associated to the 3 IRs
189193 // The goal here is to create a Tywavestate
190- val (childVariables, childScopes ) = groupIrPerElement.flatMap {
194+ val (childVariables, _ ) = groupIrPerElement.flatMap {
191195 case (elId, irs) =>
192196 logger.info(s " Element: $elId" )
193197 // Iterate over the IRs
194198 irs.flatMap {
195199 case (ir, Some (value)) =>
196- Some ((findChildVariable(elId, value, ir), findChildScopes(value)))
200+ Some ((
201+ findChildVariable(elId, value, ir, circuitChiselIR.name),
202+ Seq .empty,
203+ ))
197204 case (ir, None ) =>
198205 logger.debug(s " IR without match: $ir" , None )
199206 None
200207 }.filter { case (variableOpt, _) => variableOpt.isDefined }
201208 .map { case (variableOpt, scopes) => (variableOpt.get, scopes) }
202- }.unzip
203209
204- val scopes = Seq (tywaves_symbol_table.Scope (name = dutName, childVariables.toSeq, childScopes.flatten.toSeq))
210+ }.unzip
211+ val childScopes = findChildScopes(circuitChiselIR.name, groupIrPerElement)
212+ val scopes = Seq (tywaves_symbol_table.Scope (name = dutName, childVariables.toSeq, childScopes))
205213 // Finalize the scopes -> mergeScopes(scope) is not needed anymore
206214 val finalScopes = cleanFromFlattenedSignals(scopes)
207215
@@ -294,16 +302,23 @@ class MapChiselToVcd[T <: RawModule](generateModule: () => T, private val workin
294302 }
295303
296304 /** Find the child variables of a given tuple for a given representation */
297- private def findChildVariable [Tuple ](elId : ElId , tuple : Tuple , ir : String ): Option [tywaves_symbol_table.Variable ] =
305+ private def findChildVariable [Tuple ](
306+ elId : ElId ,
307+ tuple : Tuple ,
308+ ir : String ,
309+ moduleScope : String ,
310+ ): Option [tywaves_symbol_table.Variable ] =
298311 if (ir == " debugIR" )
299312 tuple match {
300313 case (
301- Name (name, scope, _ ),
314+ Name (name, scope, tywaveScope ),
302315 Direction (dir),
303316 HardwareType (hardwareType, size),
304317 Type (_),
305318 VerilogSignals (verilogSignals),
306319 ) =>
320+ if (moduleScope != tywaveScope)
321+ return None
307322 // Get the list of children of this variable
308323 val listChildren = gDebugIRParser.signals.filter {
309324 case (_ : ElId , (Name (_, childScope, _), Direction (_), HardwareType (_, _), Type (_), VerilogSignals (_))) =>
@@ -319,7 +334,7 @@ class MapChiselToVcd[T <: RawModule](generateModule: () => T, private val workin
319334 // TODO: Understand how to handle other types
320335 tywaves_symbol_table.realtype.Bundle (
321336 fields = listChildren.flatMap { child =>
322- findChildVariable(child._1, child._2, ir)
337+ findChildVariable(child._1, child._2, ir, moduleScope )
323338 }.toSeq,
324339 vcdName = Some (name),
325340 )
@@ -342,7 +357,63 @@ class MapChiselToVcd[T <: RawModule](generateModule: () => T, private val workin
342357 None
343358 }
344359
345- private def findChildScopes [Tuple ](value : Tuple ): Seq [tywaves_symbol_table.Scope ] =
346- // TODO: implement it to support submodules
347- Seq .empty
360+ private def findChildScopes (
361+ parentScope : String ,
362+ groupIrPerElement : Map [ElId , Seq [(String , Option [? ])]],
363+ ): Seq [tywaves_symbol_table.Scope ] = {
364+
365+ var childScopes : Seq [tywaves_symbol_table.Scope ] = Seq .empty
366+
367+ println(s " findChildScopes of: $parentScope" )
368+ gDebugIRParser.modules.foreach(println(_))
369+
370+ val childScopeNames = gDebugIRParser.modules.filter {
371+ case (_, Name (_, _, tywaveScope)) =>
372+ tywaveScope == parentScope
373+ }.map { case (_, Name (name, scope, _)) => (name, scope) }.toSet
374+
375+ childScopeNames.foreach(println)
376+
377+ childScopeNames.foreach { x =>
378+ val (childScopeName, instanceName) = x
379+ val (childVariables, _) = groupIrPerElement.flatMap {
380+ case (elId, irs) =>
381+ logger.info(s " Element: $elId" )
382+ // Iterate over the IRs
383+ irs.flatMap {
384+ case (ir, Some (value)) =>
385+ Some ((
386+ findChildVariable(elId, value, ir, childScopeName),
387+ Seq .empty,
388+ ))
389+ case (ir, None ) =>
390+ logger.debug(s " IR without match: $ir" , None )
391+ None
392+ }.filter { case (variableOpt, _) => variableOpt.isDefined }
393+ .map { case (variableOpt, scopes) => (variableOpt.get, scopes) }
394+
395+ }.unzip
396+ childScopes :+= tywaves_symbol_table.Scope (instanceName, childVariables.toSeq, findChildScopes(childScopeName, groupIrPerElement))
397+ }
398+ childScopes
399+ // val (childVariables, childScopes) = groupIrPerElement.flatMap {
400+ // case (elId, irs) =>
401+ // logger.info(s"Element: $elId")
402+ // // Iterate over the IRs
403+ // irs.flatMap {
404+ // case (ir, Some(value)) =>
405+ // Some((findChildVariable(elId, value, ir, childScope), findChildScopes(circuitChiselIR.name)))
406+ // case (ir, None) =>
407+ // logger.debug(s"IR without match: $ir", None)
408+ // None
409+ // }.filter { case (variableOpt, _) => variableOpt.isDefined }
410+ // .map { case (variableOpt, scopes) => (variableOpt.get, scopes) }
411+ //
412+ // }.unzip
413+ // Find all the child scopes of this scope
414+
415+ // Check if the scope is
416+ // Seq.empty
417+ }
418+ // TODO: implement it to support submodules
348419}
0 commit comments