Skip to content

Commit a06db79

Browse files
author
Oron Port
committed
prevent compiling the code twice when printing the backend
1 parent c5bf81a commit a06db79

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler/stages/src/main/scala/dfhdl/backends.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import dfhdl.compiler.stages.vhdl.{VHDLBackend, VHDLPrinter, VHDLDialect}
99
import dfhdl.compiler.ir.DB
1010
object backends:
1111
protected[dfhdl] class verilog(val dialect: VerilogDialect) extends BackendCompiler:
12+
def printer(
13+
cd: CompiledDesign
14+
)(using CompilerOptions, PrinterOptions): Printer =
15+
val compiledDB = cd.stagedDB
16+
new VerilogPrinter(dialect)(using compiledDB.getSet)
1217
def printer(
1318
designDB: DB
1419
)(using CompilerOptions, PrinterOptions): Printer =
@@ -24,6 +29,11 @@ object backends:
2429
val sv2017: verilog = new verilog(VerilogDialect.sv2017)
2530

2631
protected[dfhdl] class vhdl(val dialect: VHDLDialect) extends BackendCompiler:
32+
def printer(
33+
cd: CompiledDesign
34+
)(using CompilerOptions, PrinterOptions): Printer =
35+
val compiledDB = cd.stagedDB
36+
new VHDLPrinter(dialect)(using compiledDB.getSet)
2737
def printer(
2838
designDB: DB
2939
)(using CompilerOptions, PrinterOptions): Printer =

compiler/stages/src/main/scala/dfhdl/compiler/stages/BackendCompiler.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import dfhdl.options.{CompilerOptions, PrinterOptions}
55
import dfhdl.compiler.printing.Printer
66
import dfhdl.compiler.ir.DB
77

8+
//TODO: consider a way to combine the two printer methods into one,
9+
//without causing recompilation in DFApp when printing the backend code
810
trait BackendCompiler:
911
final def compile(
1012
sd: StagedDesign
1113
)(using co: CompilerOptions, po: PrinterOptions): CompiledDesign =
1214
CompiledDesign(sd.newStage(printer(sd.stagedDB).printedDB))
1315
end compile
16+
def printer(
17+
cd: CompiledDesign
18+
)(using CompilerOptions, PrinterOptions): Printer
1419
def printer(
1520
designDB: DB
1621
)(using CompilerOptions, PrinterOptions): Printer

compiler/stages/src/main/scala/dfhdl/compiler/stages/CompiledDesign.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object CompiledDesign:
1919
import StagedDesign.transform as transform2
2020
CompiledDesign(staged.transform2(transformDB))
2121
def printBackendCode(using co: CompilerOptions, po: PrinterOptions): CompiledDesign =
22-
Printer.printBackendCode(co.backend.printer(staged.stagedDB))
22+
Printer.printBackendCode(co.backend.printer(cd))
2323
cd
2424
def commit(using co: CompilerOptions): CompiledDesign =
2525
cd.transform(designDB => Printer.commit(designDB, co.topCommitPath(designDB)))

0 commit comments

Comments
 (0)