Skip to content

Commit

Permalink
Merge pull request #1219 from freechipsproject/ifdef-initial-block
Browse files Browse the repository at this point in the history
Guard initial blocks in emitted Verilog with `ifndef SYNTHESIS
  • Loading branch information
jackkoenig authored Oct 31, 2019
2 parents 68964fe + 28ffacc commit 4c3c7e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/scala/firrtl/Emitter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ class VerilogEmitter extends SeqTransform with Emitter {
emit(Seq(s" reg [$width:0] initvar;"))
}
emit(Seq("`endif"))
emit(Seq("`ifndef SYNTHESIS"))
emit(Seq("initial begin"))
emit(Seq(" `ifdef RANDOMIZE"))
emit(Seq(" `ifdef INIT_RANDOM"))
Expand All @@ -897,7 +898,8 @@ class VerilogEmitter extends SeqTransform with Emitter {
for (x <- initials) emit(Seq(tab, x))
emit(Seq(" `endif // RANDOMIZE"))
for (x <- asyncInitials) emit(Seq(tab, x))
emit(Seq("end"))
emit(Seq("end // initial"))
emit(Seq("`endif // SYNTHESIS"))
}

for ((clk, content) <- noResetAlwaysBlocks if content.nonEmpty) {
Expand Down
18 changes: 18 additions & 0 deletions src/test/scala/firrtlTests/VerilogEmitterTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,24 @@ class VerilogEmitterSpec extends FirrtlFlatSpec {
}
}

"Initial Blocks" should "be guarded by ifndef SYNTHESIS" in {
val input =
"""circuit Test :
| module Test :
| input clock : Clock
| input reset : AsyncReset
| input in : UInt<8>
| output out : UInt<8>
| reg r : UInt<8>, clock with : (reset => (reset, UInt(0)))
| r <= in
| out <= r
""".stripMargin
val state = CircuitState(parse(input), ChirrtlForm)
val result = (new VerilogCompiler).compileAndEmit(state, List())
result should containLines ("`ifndef SYNTHESIS", "initial begin")
result should containLines ("end // initial", "`endif // SYNTHESIS")
}

"Verilog name conflicts" should "be resolved" in {
val input =
"""|circuit parameter:
Expand Down

0 comments on commit 4c3c7e3

Please sign in to comment.