-
Notifications
You must be signed in to change notification settings - Fork 16
Refactor barstools for new versions of things. #35
Changes from 10 commits
6736afd
a65f560
14e301a
9209b51
6ac3291
ac9c9ad
3ccbf08
5c70e93
1789a49
3c3f2c7
0ca6fde
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// See LICENSE for license details. | ||
|
||
package barstools.macros | ||
|
||
import scala.util.matching._ | ||
|
||
sealed abstract class MemPort(val name: String) { override def toString = name } | ||
|
||
case object ReadPort extends MemPort("read") | ||
case object WritePort extends MemPort("write") | ||
case object MaskWritePort extends MemPort("mwrite") | ||
jwright6323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
case object ReadWritePort extends MemPort("rw") | ||
case object MaskReadWritePort extends MemPort("mrw") | ||
jwright6323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
object MemPort { | ||
|
||
val all = Set(ReadPort, WritePort, MaskWritePort, ReadWritePort, MaskReadWritePort) | ||
|
||
def apply(s: String): Option[MemPort] = MemPort.all.find(_.name == s) | ||
|
||
def fromString(s: String): Seq[MemPort] = { | ||
s.split(",").toSeq.map(MemPort.apply).map(_ match { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need the toSeq? |
||
case Some(x) => x | ||
case _ => throw new Exception(s"Error parsing MemPort string : ${s}") | ||
}) | ||
} | ||
} | ||
|
||
// This is based on firrtl.passes.memlib.ConfWriter | ||
// TODO standardize this in FIRRTL | ||
case class MemConf( | ||
name: String, | ||
depth: Int, | ||
width: Int, | ||
ports: Seq[MemPort], | ||
maskGranularity: Option[Int] | ||
) { | ||
|
||
private def portsStr = ports.map(_.name).mkString(",") | ||
private def maskGranStr = maskGranularity.map((p) => s"mask_gran $p").getOrElse("") | ||
|
||
override def toString() = s"name ${name} depth ${depth} width ${width} ports ${portsStr} ${maskGranStr} " | ||
} | ||
|
||
object MemConf { | ||
|
||
val regex = raw"\s*name\s+(\w+)\s+depth\s+(\d+)\s+width\s+(\d+)\s+ports\s+([^\s]+)\s+(?:mask_gran\s+(\d+))?\s*".r | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ports feels a little under specified but meh. Can you not just do |
||
|
||
def fromString(s: String): Seq[MemConf] = { | ||
s.split("\n").toSeq.map(_ match { | ||
case MemConf.regex(name, depth, width, ports, maskGran) => MemConf(name, depth.toInt, width.toInt, MemPort.fromString(ports), Option(maskGran).map(_.toInt)) | ||
case _ => throw new Exception(s"Error parsing MemConf string : ${s}") | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import firrtl.ir._ | |
import firrtl.PrimOps | ||
import firrtl.Utils.{ceilLog2, BoolType} | ||
import mdf.macrolib.{Constant, MacroPort, SRAMMacro} | ||
import mdf.macrolib.{PolarizedPort, PortPolarity, ActiveLow, ActiveHigh, NegativeEdge, PositiveEdge} | ||
import mdf.macrolib.{PolarizedPort, PortPolarity, ActiveLow, ActiveHigh, NegativeEdge, PositiveEdge, MacroExtraPort} | ||
import java.io.File | ||
import scala.language.implicitConversions | ||
|
||
|
@@ -72,6 +72,81 @@ object Utils { | |
case _ => None | ||
} | ||
} | ||
// This utility reads a conf in and returns MDF like mdf.macrolib.Utils.readMDFFromPath | ||
def readConfFromPath(path: Option[String]): Option[Seq[mdf.macrolib.Macro]] = { | ||
path.map((p) => Utils.readConfFromString(scala.io.Source.fromFile(p).mkString)) | ||
} | ||
def readConfFromString(str: String): Seq[mdf.macrolib.Macro] = { | ||
MemConf.fromString(str).map { m:MemConf => | ||
SRAMMacro(m.name, m.width, m.depth, "", Utils.portSpecToMacroPort(m.width, m.depth, m.maskGranularity, m.ports), Seq.empty[MacroExtraPort]) | ||
} | ||
} | ||
// This translates between two represenations of ports | ||
def portSpecToMacroPort(width: Int, depth: Int, maskGran: Option[Int], ports: Seq[MemPort]): Seq[MacroPort] = { | ||
var numR = 0 | ||
var numW = 0 | ||
var numRW = 0 | ||
ports.map { _ match { | ||
case ReadPort => { | ||
val portName = s"R${numR}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make a note at the top of this function where the names of these ports come from and that they are not arbitrary. |
||
numR += 1 | ||
MacroPort( | ||
width=Some(width), depth=Some(depth), | ||
address=PolarizedPort(s"${portName}_addr", ActiveHigh), | ||
clock=PolarizedPort(s"${portName}_clk", PositiveEdge), | ||
chipEnable=Some(PolarizedPort(s"${portName}_en", ActiveHigh)), | ||
output=Some(PolarizedPort(s"${portName}_data", ActiveHigh)) | ||
) } | ||
case WritePort => { | ||
val portName = s"W${numW}" | ||
numW += 1 | ||
MacroPort( | ||
width=Some(width), depth=Some(depth), | ||
address=PolarizedPort(s"${portName}_addr", ActiveHigh), | ||
clock=PolarizedPort(s"${portName}_clk", PositiveEdge), | ||
writeEnable=Some(PolarizedPort(s"${portName}_en", ActiveHigh)), | ||
input=Some(PolarizedPort(s"${portName}_data", ActiveHigh)) | ||
) } | ||
case MaskWritePort => { | ||
val portName = s"W${numW}" | ||
numW += 1 | ||
MacroPort( | ||
width=Some(width), depth=Some(depth), | ||
address=PolarizedPort(s"${portName}_addr", ActiveHigh), | ||
clock=PolarizedPort(s"${portName}_clk", PositiveEdge), | ||
writeEnable=Some(PolarizedPort(s"${portName}_en", ActiveHigh)), | ||
maskPort=Some(PolarizedPort(s"${portName}_mask", ActiveHigh)), | ||
maskGran=maskGran, | ||
input=Some(PolarizedPort(s"${portName}_data", ActiveHigh)) | ||
) } | ||
case ReadWritePort => { | ||
val portName = s"RW${numRW}" | ||
numRW += 1 | ||
MacroPort( | ||
width=Some(width), depth=Some(depth), | ||
address=PolarizedPort(s"${portName}_addr", ActiveHigh), | ||
clock=PolarizedPort(s"${portName}_clk", PositiveEdge), | ||
chipEnable=Some(PolarizedPort(s"${portName}_en", ActiveHigh)), | ||
writeEnable=Some(PolarizedPort(s"${portName}_wmode", ActiveHigh)), | ||
input=Some(PolarizedPort(s"${portName}_wdata", ActiveHigh)), | ||
output=Some(PolarizedPort(s"${portName}_rdata", ActiveHigh)) | ||
) } | ||
case MaskReadWritePort => { | ||
val portName = s"RW${numRW}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just trusting the number is correct here. |
||
numRW += 1 | ||
MacroPort( | ||
width=Some(width), depth=Some(depth), | ||
address=PolarizedPort(s"${portName}_addr", ActiveHigh), | ||
clock=PolarizedPort(s"${portName}_clk", PositiveEdge), | ||
chipEnable=Some(PolarizedPort(s"${portName}_en", ActiveHigh)), | ||
writeEnable=Some(PolarizedPort(s"${portName}_wmode", ActiveHigh)), | ||
maskPort=Some(PolarizedPort(s"${portName}_wmask", ActiveHigh)), | ||
maskGran=maskGran, | ||
input=Some(PolarizedPort(s"${portName}_wdata", ActiveHigh)), | ||
output=Some(PolarizedPort(s"${portName}_rdata", ActiveHigh)) | ||
) } | ||
}} | ||
} | ||
def findSRAMCompiler(s: Option[Seq[mdf.macrolib.Macro]]): Option[mdf.macrolib.SRAMCompiler] = { | ||
s match { | ||
case Some(l:Seq[mdf.macrolib.Macro]) => | ||
|
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sbt.version=0.13.12 | ||
sbt.version=1.2.7 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5") | ||
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if they specify both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will take the last option specified. I think this is intuitive enough behavior to leave it as is.