@@ -56,11 +56,12 @@ private[chisel3] object Serializer {
5656
5757 // TODO use makeMessage to get ':' filename col separator instead of space
5858 // Can we optimize the escaping?
59- private def serialize (info : SourceInfo )(implicit b : StringBuilder ): Unit = info match {
60- case _ : NoSourceInfo => ()
61- case sl : SourceLine =>
62- b ++= " @[" ; b ++= fir.FileInfo .fromUnescaped(sl.serialize).escaped; b ++= " ]"
63- }
59+ private def serialize (info : SourceInfo )(implicit b : StringBuilder , suppressSourceInfo : Boolean ): Unit =
60+ info match {
61+ case sl : SourceLine if ! suppressSourceInfo =>
62+ b ++= " @[" ; b ++= fir.FileInfo .fromUnescaped(sl.serialize).escaped; b ++= " ]"
63+ case _ => ()
64+ }
6465
6566 private def reportInternalError (msg : String ): Nothing = {
6667 val link = " https://github.com/chipsalliance/chisel/issues/new"
@@ -164,7 +165,7 @@ private[chisel3] object Serializer {
164165 args : Seq [Arg ],
165166 params : Seq [(String , Param )],
166167 typeAliases : Seq [String ]
167- )(implicit b : StringBuilder ): Unit = {
168+ )(implicit b : StringBuilder , suppressSourceInfo : Boolean ): Unit = {
168169 if (name.nonEmpty) {
169170 b ++= " node " ; b ++= legalize(name.get); b ++= " = "
170171 }
@@ -192,8 +193,9 @@ private[chisel3] object Serializer {
192193
193194 /** Serialize Commands */
194195 private def serializeSimpleCommand (cmd : Command , ctx : Component , typeAliases : Seq [String ])(
195- implicit b : StringBuilder ,
196- indent : Int
196+ implicit b : StringBuilder ,
197+ indent : Int ,
198+ suppressSourceInfo : Boolean
197199 ): Unit = cmd match {
198200 case e : DefPrim [_] =>
199201 b ++= " node " ; b ++= legalize(e.name); b ++= " = " ;
@@ -321,8 +323,9 @@ private[chisel3] object Serializer {
321323 }
322324
323325 private def serializeCommand (cmd : Command , ctx : Component , typeAliases : Seq [String ])(
324- implicit indent : Int
325- ): Iterator [String ] =
326+ implicit indent : Int ,
327+ suppressSourceInfo : Boolean
328+ ): Iterator [String ] = {
326329 cmd match {
327330 case When (info, pred, ifRegion, elseRegion) =>
328331 val start = {
@@ -338,13 +341,15 @@ private[chisel3] object Serializer {
338341 newLineNoIndent()
339342 Iterator (b.toString)
340343 } else {
341- ifRegion.flatMap(serializeCommand(_, ctx, typeAliases)(indent + 1 ))
344+ ifRegion.flatMap(serializeCommand(_, ctx, typeAliases)(indent + 1 , suppressSourceInfo ))
342345 }
343346 val end = if (elseRegion.nonEmpty) {
344347 implicit val b = new StringBuilder
345348 doIndent(); b ++= " else :"
346349 newLineNoIndent()
347- Iterator (b.toString) ++ elseRegion.flatMap(serializeCommand(_, ctx, typeAliases)(indent + 1 ))
350+ Iterator (b.toString) ++ elseRegion.flatMap(
351+ serializeCommand(_, ctx, typeAliases)(indent + 1 , suppressSourceInfo)
352+ )
348353 } else Iterator .empty
349354 start ++ middle ++ end
350355 case LayerBlock (info, layer, region) =>
@@ -354,15 +359,15 @@ private[chisel3] object Serializer {
354359 newLineNoIndent()
355360 Iterator (b.toString)
356361 }
357- start ++ region.iterator.flatMap(serializeCommand(_, ctx, typeAliases)(indent + 1 ))
362+ start ++ region.iterator.flatMap(serializeCommand(_, ctx, typeAliases)(indent + 1 , suppressSourceInfo ))
358363 case Placeholder (_, block) =>
359364 if (block.isEmpty) {
360365 implicit val b = new StringBuilder
361366 doIndent(); b ++= " skip"
362367 newLineNoIndent()
363368 Iterator (b.toString)
364369 } else {
365- block.iterator.flatMap(serializeCommand(_, ctx, typeAliases))
370+ block.iterator.flatMap(serializeCommand(_, ctx, typeAliases)(indent, suppressSourceInfo) )
366371 }
367372 case cmd @ DefContract (info, names, exprs) =>
368373 val start = {
@@ -382,7 +387,9 @@ private[chisel3] object Serializer {
382387 newLineNoIndent()
383388 Iterator (b.toString)
384389 }
385- start ++ cmd.region.getAllCommands().flatMap(serializeCommand(_, ctx, typeAliases)(indent + 1 ))
390+ start ++ cmd.region
391+ .getAllCommands()
392+ .flatMap(serializeCommand(_, ctx, typeAliases)(indent + 1 , suppressSourceInfo))
386393 // TODO can we avoid checking 4 less common Commands every single time?
387394 case simple =>
388395 // TODO avoid Iterator boxing for every simple command
@@ -392,6 +399,7 @@ private[chisel3] object Serializer {
392399 newLineNoIndent()
393400 Iterator (b.toString)
394401 }
402+ }
395403
396404 /** Serialize Chisel IR Block into FIRRTL Statements
397405 *
@@ -403,7 +411,8 @@ private[chisel3] object Serializer {
403411 * @return Iterator[String] of the equivalent FIRRTL text
404412 */
405413 private def serialize (block : Block , ctx : Component , typeAliases : Seq [String ])(
406- implicit indent : Int
414+ implicit indent : Int ,
415+ suppressSourceInfo : Boolean
407416 ): Iterator [String ] = {
408417 val commands = block.getCommands()
409418 val secretCommands = block.getSecretCommands()
@@ -414,7 +423,7 @@ private[chisel3] object Serializer {
414423 return Iterator (b.toString)
415424 } else {
416425 Iterator .empty[String ] ++ (commands.iterator ++ secretCommands).flatMap(c =>
417- serializeCommand(c, ctx, typeAliases)
426+ serializeCommand(c, ctx, typeAliases)(indent, suppressSourceInfo)
418427 )
419428 }
420429 }
@@ -547,7 +556,7 @@ private[chisel3] object Serializer {
547556 port : Port ,
548557 typeAliases : Seq [String ],
549558 topDir : SpecifiedDirection = SpecifiedDirection .Unspecified
550- )(implicit b : StringBuilder , indent : Int ): Unit = {
559+ )(implicit b : StringBuilder , indent : Int , suppressSourceInfo : Boolean ): Unit = {
551560 val resolvedDir = SpecifiedDirection .fromParent(topDir, firrtlUserDirOf(port.id))
552561 val dir = resolvedDir match {
553562 case SpecifiedDirection .Unspecified | SpecifiedDirection .Output => " output"
@@ -565,7 +574,10 @@ private[chisel3] object Serializer {
565574 }
566575
567576 // TODO what is typeAliases for? Should it be a Set?
568- private def serialize (component : Component , typeAliases : Seq [String ])(implicit indent : Int ): Iterator [String ] =
577+ private def serialize (component : Component , typeAliases : Seq [String ])(
578+ implicit indent : Int ,
579+ suppressSourceInfo : Boolean
580+ ): Iterator [String ] = {
569581 component match {
570582 case ctx @ DefModule (id, name, public, layers, ports, block) =>
571583 val start = {
@@ -581,7 +593,7 @@ private[chisel3] object Serializer {
581593 newLineNoIndent() // newline for body, serialize(body) will indent
582594 b.toString
583595 }
584- Iterator (start) ++ serialize(block, ctx, typeAliases)(indent + 1 )
596+ Iterator (start) ++ serialize(block, ctx, typeAliases)(indent + 1 , suppressSourceInfo )
585597
586598 case ctx @ DefBlackBox (id, name, ports, topDir, params, knownLayers) =>
587599 implicit val b = new StringBuilder
@@ -616,7 +628,7 @@ private[chisel3] object Serializer {
616628 newLineNoIndent() // newline for body, serialize(body) will indent
617629 b.toString
618630 }
619- Iterator (start) ++ serialize(block, ctx, typeAliases)(indent + 1 )
631+ Iterator (start) ++ serialize(block, ctx, typeAliases)(indent + 1 , suppressSourceInfo )
620632
621633 case ctx @ DefFormalTest (name, module, params, sourceInfo) =>
622634 implicit val b = new StringBuilder
@@ -627,8 +639,9 @@ private[chisel3] object Serializer {
627639 }
628640 Iterator (b.toString)
629641 }
642+ }
630643
631- private def serialize (layer : Layer )(implicit b : StringBuilder , indent : Int ): Unit = {
644+ private def serialize (layer : Layer )(implicit b : StringBuilder , indent : Int , suppressSourceInfo : Boolean ): Unit = {
632645 newLineAndIndent()
633646 b ++= " layer "
634647 b ++= layer.name
@@ -647,13 +660,13 @@ private[chisel3] object Serializer {
647660 }
648661 b ++= " :"
649662 serialize(layer.sourceInfo)
650- layer.children.foreach(serialize(_)(b, indent + 1 ))
663+ layer.children.foreach(serialize(_)(b, indent + 1 , suppressSourceInfo ))
651664 }
652665
653- private def serialize (layers : Seq [Layer ])(implicit indent : Int ): Iterator [String ] = {
666+ private def serialize (layers : Seq [Layer ])(implicit indent : Int , suppressSourceInfo : Boolean ): Iterator [String ] = {
654667 if (layers.nonEmpty) {
655668 implicit val b = new StringBuilder
656- layers.foreach(serialize)
669+ layers.foreach(serialize(_)(b, indent, suppressSourceInfo) )
657670 newLineNoIndent()
658671 Iterator (b.toString)
659672 } else Iterator .empty
@@ -667,7 +680,8 @@ private[chisel3] object Serializer {
667680
668681 // TODO make Annotation serialization lazy
669682 private def serialize (circuit : Circuit , annotations : Seq [Annotation ]): Iterator [String ] = {
670- implicit val indent : Int = 0
683+ implicit val indent : Int = 0
684+ implicit val suppressSourceInfo : Boolean = circuit.suppressSourceInfo
671685 val prelude = {
672686 implicit val b = new StringBuilder
673687 b ++= s " FIRRTL version $version\n "
@@ -698,7 +712,7 @@ private[chisel3] object Serializer {
698712 b += NewLine
699713 Iterator (b.toString)
700714 } else Iterator .empty
701- val layers = serialize(circuit.layers)(indent + 1 )
715+ val layers = serialize(circuit.layers)(indent + 1 , suppressSourceInfo )
702716 // TODO what is typeAliases for? Should it be a Set?
703717 val typeAliasesSeq : Seq [String ] = circuit.typeAliases.map(_.name)
704718 prelude ++
@@ -707,7 +721,7 @@ private[chisel3] object Serializer {
707721 layers ++
708722 circuit.components.iterator.zipWithIndex.flatMap { case (m, i) =>
709723 val newline = Iterator (if (i == 0 ) s " $NewLine" else s " ${NewLine }${NewLine }" )
710- newline ++ serialize(m, typeAliasesSeq)(indent + 1 )
724+ newline ++ serialize(m, typeAliasesSeq)(indent + 1 , suppressSourceInfo )
711725 } ++
712726 Iterator (s " $NewLine" )
713727 }
0 commit comments