File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed
core/src/main/scala/chisel3/properties
firrtl/src/main/scala/firrtl/ir
src/test/scala/chiselTests/properties Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ private[chisel3] object PropertyType extends LowPriorityPropertyTypeInstances {
147147 }
148148
149149 implicit val stringPropertyTypeInstance : SimplePropertyType [String ] =
150- makeSimple[String ](fir.StringPropertyType , fir.StringPropertyLiteral (_ ))
150+ makeSimple[String ](fir.StringPropertyType , s => fir.StringPropertyLiteral (s ))
151151
152152 implicit val boolPropertyTypeInstance : SimplePropertyType [Boolean ] =
153153 makeSimple[Boolean ](fir.BooleanPropertyType , fir.BooleanPropertyLiteral (_))
Original file line number Diff line number Diff line change @@ -113,7 +113,7 @@ object Serializer {
113113 case DoublePropertyLiteral (value) =>
114114 b ++= " Double(" ; b ++= value.toString(); b ++= " )"
115115 case StringPropertyLiteral (value) =>
116- b ++= " String(\" " ; b ++= value; b ++= " \ " )"
116+ b ++= " String(" ; b ++= StringLit ( value).escape ; b ++= " )"
117117 case BooleanPropertyLiteral (value) =>
118118 b ++= s " Bool( ${value}) "
119119 case PathPropertyLiteral (value) =>
Original file line number Diff line number Diff line change @@ -132,6 +132,31 @@ class PropertySpec extends ChiselFlatSpec with MatchesAndOmits {
132132 )()
133133 }
134134
135+ it should " escape special characters in Property String literals" in {
136+ val input = " foo\"\n\t\\ bar"
137+ val expected = """ foo\"\n\t\\ bar"""
138+ val chirrtl = ChiselStage .emitCHIRRTL(new RawModule {
139+ val propOut = IO (Output (Property [String ]()))
140+ propOut := Property (input)
141+ })
142+
143+ matchesAndOmits(chirrtl)(
144+ s """ propassign propOut, String(" $expected") """
145+ )()
146+ }
147+
148+ it should " not escape characters that do not need escaping in Property String literals" in {
149+ val input = " foo!@#$%^&*()_+bar"
150+ val chirrtl = ChiselStage .emitCHIRRTL(new RawModule {
151+ val propOut = IO (Output (Property [String ]()))
152+ propOut := Property (input)
153+ })
154+
155+ matchesAndOmits(chirrtl)(
156+ s """ propassign propOut, String(" $input") """
157+ )()
158+ }
159+
135160 it should " support Boolean as a Property type" in {
136161 val chirrtl = ChiselStage .emitCHIRRTL(new RawModule {
137162 val boolProp = IO (Input (Property [Boolean ]()))
You can’t perform that action at this time.
0 commit comments