Skip to content

Commit

Permalink
Merge pull request #174 from DFiantHDL/nextbatch
Browse files Browse the repository at this point in the history
v0.7.0 update batch
  • Loading branch information
soronpo authored Aug 27, 2024
2 parents 3512eae + ba5a24c commit 03d5e1c
Show file tree
Hide file tree
Showing 32 changed files with 491 additions and 262 deletions.
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commands += DFHDLCommands.quickTestSetup

// format: off
val projectName = "dfhdl"
val compilerVersion = "3.4.2"
val compilerVersion = "3.5.0"

inThisBuild(
List(
Expand Down Expand Up @@ -133,20 +133,20 @@ lazy val dependencies =
private val scalafmtV = "3.8.2"
private val airframelogV = "24.8.0"
private val oslibV = "0.9.2"
private val scoptV = "4.1.0"
private val scallopV = "5.1.0"
val scodec = "org.scodec" %% "scodec-bits" % scodecV
val munit = "org.scalameta" %% "munit" % munitV % Test
val scalafmt = ("org.scalameta" %% "scalafmt-dynamic" % scalafmtV).cross(CrossVersion.for3Use2_13)
val airframelog = "org.wvlet.airframe" %% "airframe-log" % airframelogV
val oslib = "com.lihaoyi" %% "os-lib" % oslibV
val scopt = "com.github.scopt" %% "scopt" % scoptV
val scallop = "org.rogach" %% "scallop" % scallopV
}

lazy val commonDependencies = Seq(
dependencies.scodec,
dependencies.munit,
dependencies.airframelog,
dependencies.scopt
dependencies.scallop
)

// SETTINGS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ trait AbstractOwnerPrinter extends AbstractPrinter:
def csDFDesignDefInst(design: DFDesignBlock): String
def csBlockBegin: String
def csBlockEnd: String
def csDFIfGuard(ifBlock: DFConditional.DFIfElseBlock): String = ifBlock.guardRef.refCodeString
def csDFIfStatement(csCond: String): String
def csDFElseStatement: String
def csDFElseIfStatement(csCond: String): String
final def csDFIfElseStatement(ifBlock: DFConditional.DFIfElseBlock): String =
ifBlock.prevBlockOrHeaderRef.get match
case _: DFConditional.Header => csDFIfStatement(ifBlock.guardRef.refCodeString)
case _: DFConditional.Header => csDFIfStatement(csDFIfGuard(ifBlock))
case _ =>
ifBlock.guardRef.get match
case DFMember.Empty => csDFElseStatement
case _ => csDFElseIfStatement(ifBlock.guardRef.refCodeString)
case _ => csDFElseIfStatement(csDFIfGuard(ifBlock))
def csDFIfEnd(lastCB: DFConditional.DFIfElseBlock): String
def csIfBlockEmpty: String
def csDFCaseBlockEmpty: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,11 @@ end Printer

object Printer:
def printGenFiles(db: DB)(using po: PrinterOptions): Unit =
val srcFiles =
if (po.showGlobals) db.srcFiles
else db.srcFiles.drop(1)
val srcTypeFilter: SourceType => Boolean =
if (po.showGlobals)
srcType => srcType == SourceType.Design.Regular | srcType == SourceType.Design.GlobalDef
else srcType => srcType == SourceType.Design.Regular
val srcFiles = db.srcFiles.view.filter(srcFile => srcTypeFilter(srcFile.sourceType))
srcFiles.foreach {
case srcFile @ SourceFile(
SourceOrigin.Compiled | SourceOrigin.Committed,
Expand Down
7 changes: 2 additions & 5 deletions compiler/ir/src/main/scala/dfhdl/options/PrinterOptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dfhdl.options
import dfhdl.compiler.ir
import dfhdl.internals.simplePattenToRegex
import dfhdl.options.PrinterOptions.*
import dfhdl.internals.scastieIsRunning

final case class PrinterOptions(
align: Align,
Expand All @@ -11,10 +12,6 @@ final case class PrinterOptions(
)
object PrinterOptions:

// detecting if running in Scastie by checking the PWD
private def inScastie: Boolean =
System.getProperty("user.dir").startsWith("/tmp/scastie")

// disabling color if in Scastie because of https://github.com/scalacenter/scastie/issues/492
given default(using
align: Align,
Expand All @@ -36,7 +33,7 @@ object PrinterOptions:

opaque type Color <: Boolean = Boolean
object Color:
given Color = !inScastie
given Color = !scastieIsRunning
given Conversion[Boolean, Color] = identity

opaque type ShowGlobals <: Boolean = Boolean
Expand Down
2 changes: 2 additions & 0 deletions compiler/stages/src/main/scala/dfhdl/backends.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object backends:
)(using CompilerOptions, PrinterOptions): Printer =
val compiledDB = StageRunner.run(VerilogBackend)(designDB)
new VerilogPrinter(dialect)(using compiledDB.getSet)
override def toString(): String = s"verilog.$dialect"
object verilog extends verilog(VerilogDialect.sv2005):
val v2001: verilog = new verilog(VerilogDialect.v2001)
val sv2005: verilog = this
Expand All @@ -26,6 +27,7 @@ object backends:
)(using CompilerOptions, PrinterOptions): Printer =
val compiledDB = StageRunner.run(VHDLBackend)(designDB)
new VHDLPrinter(dialect)(using compiledDB.getSet)
override def toString(): String = s"vhdl.$dialect"
object vhdl extends vhdl(VHDLDialect.v2008):
val v93: vhdl = new vhdl(VHDLDialect.v93)
val v2008: vhdl = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ protected trait VHDLOwnerPrinter extends AbstractOwnerPrinter:
def csDFDesignDefInst(design: DFDesignBlock): String = printer.unsupported
def csBlockBegin: String = ""
def csBlockEnd: String = ""
override def csDFIfGuard(ifBlock: DFConditional.DFIfElseBlock): String =
val requiresBoolConv =
if (printer.inVHDL93)
ifBlock.guardRef.get.asInstanceOf[DFVal].dfType match
case DFBit => true
case _ => false
else false
if (requiresBoolConv) s"to_bool(${super.csDFIfGuard(ifBlock)})"
else super.csDFIfGuard(ifBlock)
def csDFIfStatement(csCond: String): String = s"if $csCond then"
def csDFElseStatement: String = "else"
def csDFElseIfStatement(csCond: String): String = s"elsif $csCond then"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class VHDLPrinter(val dialect: VHDLDialect)(using
VHDLOwnerPrinter:
type TPrinter = VHDLPrinter
given printer: TPrinter = this
val inVHDL93: Boolean = dialect match
case VHDLDialect.v93 => true
case _ => false
def unsupported: Nothing = throw new IllegalArgumentException(
"Unsupported member for this RTPrinter."
)
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/dfhdl/core/DFIf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected[core] def analyzeControlRet(ret: Any)(using DFC): DFTypeAny = Exact.st

object DFIf:
def singleBranch[R](
condOption: Option[DFValOf[DFBool]],
condOption: Option[DFValOf[DFBoolOrBit]],
prevBlockOrHeader: DFOwnerAny | DFValAny,
run: () => R
)(using
Expand All @@ -32,7 +32,7 @@ object DFIf:
(dfType, block)
end singleBranch
def fromBranches[R](
branches: List[(DFValOf[DFBool], () => R)],
branches: List[(DFValOf[DFBoolOrBit], () => R)],
elseOption: Option[() => R]
)(using DFC): R = try
val header = Header(DFUnit)
Expand Down Expand Up @@ -94,7 +94,7 @@ object DFIf:

object Block:
def apply(
guardOption: Option[DFValOf[DFBool]],
guardOption: Option[DFValOf[DFBoolOrBit]],
prevBlockOrHeader: DFOwnerAny | DFValAny
)(using
DFC
Expand Down
13 changes: 2 additions & 11 deletions core/src/main/scala/dfhdl/options/OnError.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
package dfhdl.options
import dfhdl.internals.getShellCommand
import dfhdl.internals.{sbtShellIsRunning, sbtTestIsRunning}

enum OnError derives CanEqual:
case Exit, Exception
object OnError:
private val possibleCommandsSuffix = List(
"xsbt.boot.Boot",
"xsbt.boot.Boot test",
"sbt-launch.jar",
"sbt-launch.jar test"
)
private lazy val sbtShellOrTestIsRunning = getShellCommand match
case Some(cmd) if possibleCommandsSuffix.exists(suf => cmd.endsWith(suf)) => true
case _ => false
given OnError = if (sbtShellOrTestIsRunning) Exception else Exit
given OnError = if (sbtShellIsRunning || sbtTestIsRunning) Exception else Exit
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pygments==2.18.0
mkdocs==1.6.0
mkdocs-material==9.5.31
mkdocs-material==9.5.33
pymdown-extensions==10.9
mkdocs-redirects==1.2.1
mkdocs-glightbox==0.4.0
Expand Down
7 changes: 7 additions & 0 deletions internals/src/main/scala/dfhdl/internals/MetaContext.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ final case class Position(

object Position:
val unknown = Position("", 0, 0, 0, 0)
def fromAbsPath(
fileAbsPath: String,
lineStart: Int,
columnStart: Int,
lineEnd: Int,
columnEnd: Int
): Position = Position(getRelativePath(fileAbsPath), lineStart, columnStart, lineEnd, columnEnd)

trait MetaContext:
def setMeta(
Expand Down
25 changes: 24 additions & 1 deletion internals/src/main/scala/dfhdl/internals/helpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ extension [T](seq: Iterable[T])
accumulator(seq.drop(subseq.size), f, (key -> subseq) :: res)
accumulator(seq, f, Nil).view.map(e => (e._1, e._2.toList)).toList

def getShellCommand: Option[String] =
lazy val getShellCommand: Option[String] =
import scala.io.Source
import scala.util.{Try, Success, Failure}
import sys.process.*
Expand All @@ -356,3 +356,26 @@ def getShellCommand: Option[String] =
case Failure(_) => None
end match
end getShellCommand

lazy val sbtShellIsRunning: Boolean =
getShellCommand.exists(cmd => cmd.endsWith("xsbt.boot.Boot") || cmd.endsWith("sbt-launch.jar"))

lazy val sbtTestIsRunning: Boolean =
getShellCommand.exists(cmd =>
cmd.endsWith("xsbt.boot.Boot test") || cmd.endsWith("sbt-launch.jar test")
)

lazy val sbtIsRunning: Boolean =
getShellCommand.exists(cmd => cmd.contains("xsbt.boot.Boot") || cmd.contains("sbt-launch.jar"))

lazy val scala_cliIsRunning: Boolean = getShellCommand.exists(_.contains(".scala-build"))

// detecting if running in Scastie by checking the PWD
lazy val scastieIsRunning: Boolean =
System.getProperty("user.dir").startsWith("/tmp/scastie")

def getRelativePath(absolutePathStr: String): String =
import java.nio.file.Paths
val absolutePath = Paths.get(absolutePathStr).toAbsolutePath()
val currentDir = Paths.get("").toAbsolutePath()
currentDir.relativize(absolutePath).toString
Loading

0 comments on commit 03d5e1c

Please sign in to comment.