Change macrocompiler to support FIRRTL 1.3 -- not backwards compatible

This commit is contained in:
Albert Magyar
2020-05-06 21:40:47 +00:00
parent acda0a3490
commit 757c39ac1c
2 changed files with 22 additions and 30 deletions

View File

@@ -289,8 +289,8 @@ class MacroCompilerPass(mems: Option[Seq[Macro]],
* address bits into account. */ * address bits into account. */
if (mem.src.depth > lib.src.depth) { if (mem.src.depth > lib.src.depth) {
mem.src.ports foreach { port => mem.src.ports foreach { port =>
val high = ceilLog2(mem.src.depth) val high = MacroCompilerMath.ceilLog2(mem.src.depth)
val low = ceilLog2(lib.src.depth) val low = MacroCompilerMath.ceilLog2(lib.src.depth)
val ref = WRef(port.address.name) val ref = WRef(port.address.name)
val nodeName = s"${ref.name}_sel" val nodeName = s"${ref.name}_sel"
val tpe = UIntType(IntWidth(high-low)) val tpe = UIntType(IntWidth(high-low))
@@ -738,7 +738,7 @@ class MacroCompiler extends Compiler {
def transforms: Seq[Transform] = def transforms: Seq[Transform] =
Seq(new MacroCompilerTransform) ++ Seq(new MacroCompilerTransform) ++
getLoweringTransforms(firrtl.HighForm, firrtl.LowForm) ++ getLoweringTransforms(firrtl.ChirrtlForm, firrtl.LowForm) ++
Seq(new MacroCompilerOptimizations) Seq(new MacroCompilerOptimizations)
} }
@@ -834,36 +834,24 @@ object MacroCompiler extends App {
) )
)) ))
) )
// Append a NoDCEAnnotation to avoid dead code elimination removing the non-parent SRAMs
val state = CircuitState(circuit, HighForm, annotations :+ NoDCEAnnotation)
// Run the compiler. // The actual MacroCompilerTransform basically just generates an input circuit
val result = new MacroCompiler().compileAndEmit(state) val macroCompilerInput = CircuitState(circuit, HighForm, annotations)
val macroCompiled = (new MacroCompilerTransform).execute(macroCompilerInput)
// Write output FIRRTL file.
params.get(Firrtl) match { // Since the MacroCompiler defines its own CLI, reconcile this with FIRRTL options
case Some(firrtlFile: String) => { val firOptions = new ExecutionOptionsManager("macrocompiler") with HasFirrtlOptions {
val fileWriter = new FileWriter(new File(firrtlFile)) firrtlOptions = FirrtlExecutionOptions(
fileWriter.write(result.circuit.serialize) outputFileNameOverride = params.get(Verilog).getOrElse(""),
fileWriter.close() noDCE = true,
} firrtlSource = Some(macroCompiled.circuit.serialize)
case None => )
} }
// Write output Verilog file. // Run FIRRTL compiler
params.get(Verilog) match { Driver.execute(firOptions)
case Some(verilogFile: String) => {
// Open the writer for the output Verilog file.
val verilogWriter = new FileWriter(new File(verilogFile))
// Extract Verilog circuit and write it.
verilogWriter.write(result.getEmittedCircuit.value)
// Close the writer.
verilogWriter.close()
}
case None =>
}
params.get(HammerIR) match { params.get(HammerIR) match {
case Some(hammerIRFile: String) => { case Some(hammerIRFile: String) => {
val lines = Source.fromFile(hammerIRFile).getLines().toList val lines = Source.fromFile(hammerIRFile).getLines().toList

View File

@@ -6,12 +6,16 @@ import firrtl._
import firrtl.ir._ import firrtl.ir._
import firrtl.PrimOps import firrtl.PrimOps
import firrtl.passes.memlib.{MemConf, MemPort, ReadPort, WritePort, ReadWritePort, MaskedWritePort, MaskedReadWritePort} import firrtl.passes.memlib.{MemConf, MemPort, ReadPort, WritePort, ReadWritePort, MaskedWritePort, MaskedReadWritePort}
import firrtl.Utils.{ceilLog2, BoolType} import firrtl.Utils.BoolType
import mdf.macrolib.{Constant, MacroPort, SRAMMacro} import mdf.macrolib.{Constant, MacroPort, SRAMMacro}
import mdf.macrolib.{PolarizedPort, PortPolarity, ActiveLow, ActiveHigh, NegativeEdge, PositiveEdge, MacroExtraPort} import mdf.macrolib.{PolarizedPort, PortPolarity, ActiveLow, ActiveHigh, NegativeEdge, PositiveEdge, MacroExtraPort}
import java.io.File import java.io.File
import scala.language.implicitConversions import scala.language.implicitConversions
object MacroCompilerMath {
def ceilLog2(x: BigInt): Int = (x-1).bitLength
}
class FirrtlMacroPort(port: MacroPort) { class FirrtlMacroPort(port: MacroPort) {
val src = port val src = port
@@ -19,7 +23,7 @@ class FirrtlMacroPort(port: MacroPort) {
val isWriter = port.input.nonEmpty && port.output.isEmpty val isWriter = port.input.nonEmpty && port.output.isEmpty
val isReadWriter = port.input.nonEmpty && port.output.nonEmpty val isReadWriter = port.input.nonEmpty && port.output.nonEmpty
val addrType = UIntType(IntWidth(ceilLog2(port.depth.get) max 1)) val addrType = UIntType(IntWidth(MacroCompilerMath.ceilLog2(port.depth.get) max 1))
val dataType = UIntType(IntWidth(port.width.get)) val dataType = UIntType(IntWidth(port.width.get))
val maskType = UIntType(IntWidth(port.width.get / port.effectiveMaskGran)) val maskType = UIntType(IntWidth(port.width.get / port.effectiveMaskGran))