Skip to content

Commit

Permalink
Merge pull request #3754 from chipsalliance/panama-refactor
Browse files Browse the repository at this point in the history
Refactor panama binding and converter framwork
  • Loading branch information
sequencer authored Jan 22, 2024
2 parents 6e83eb9 + 4694f41 commit b37180d
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 429 deletions.
185 changes: 0 additions & 185 deletions binder/src/test/scala/BinderSpec.scala

This file was deleted.

55 changes: 32 additions & 23 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -231,45 +231,53 @@ trait ChiselPublishModule extends PublishModule {
def publishVersion = "5.0-SNAPSHOT"
}

object circtpanamabinder extends Cross[CIRCTPanamaBinder](v.scalaCrossVersions)
object circtpanamabinding extends CIRCTPanamaBinding

trait CIRCTPanamaBinder
extends common.CIRCTPanamaBinderModule
with ChiselPublishModule
with CrossSbtModule
with ScalafmtModule {
def millSourcePath = super.millSourcePath / os.up / "binder"
trait CIRCTPanamaBinding
extends common.CIRCTPanamaBindingModule
with ChiselPublishModule {

def header = T(PathRef(millSourcePath / "jextract-headers.h"))

def circtInstallPath = T.input(os.Path(T.ctx.env.get("CIRCT_INSTALL_PATH").getOrElse("/usr/local")))
def circtInstallPath = T.input(os.Path(T.ctx().env.get("CIRCT_INSTALL_PATH").getOrElse("/usr/local")))

def includePaths = T(Seq(PathRef(circtInstallPath() / "include")))

def libraryPaths = T(Seq(PathRef(circtInstallPath() / "lib")))
}

def chiselModule = chisel(crossScalaVersion)
object panamalib extends Cross[PanamaLib](v.scalaCrossVersions)

def pluginModule = plugin(crossScalaVersion)
trait PanamaLib
extends common.PanamaLibModule
with CrossModuleBase
with ChiselPublishModule
with ScalafmtModule {
def circtPanamaBindingModule = circtpanamabinding
}

object bindertest extends Cross[CIRCTPanamaBinderModuleTest](v.scalaCrossVersions)
object panamaom extends Cross[PanamaOM](v.scalaCrossVersions)

trait CIRCTPanamaBinderModuleTest
extends tests.CIRCTPanamaBinderModuleTestModule
trait PanamaOM
extends common.PanamaOMModule
with CrossModuleBase
with ChiselPublishModule
with ScalafmtModule {
override def millSourcePath = circtpanamabinder(crossScalaVersion).millSourcePath
def panamaLibModule = panamalib(crossScalaVersion)
}

def circtPanamaBinderModule = circtpanamabinder(crossScalaVersion)
object panamaconverter extends Cross[PanamaConverter](v.scalaCrossVersions)

def scalatestIvy = v.scalatest
trait PanamaConverter
extends common.PanamaConverterModule
with CrossModuleBase
with ChiselPublishModule
with ScalafmtModule {
def panamaOMModule = panamaom(crossScalaVersion)

def scalacheckIvy = v.scalacheck
def chiselModule = chisel(crossScalaVersion)

override def sources = T.sources {
Seq(PathRef(millSourcePath / "src" / "test"))
}
def pluginModule = plugin(crossScalaVersion)
}

object litutility extends Cross[LitUtility](v.scalaCrossVersions)
Expand All @@ -279,7 +287,8 @@ trait LitUtility
with CrossModuleBase
with ScalafmtModule {
def millSourcePath = super.millSourcePath / os.up / "lit" / "utility"
def circtPanamaBinderModule = circtpanamabinder(crossScalaVersion)
def panamaConverterModule = panamaconverter(crossScalaVersion)
def panamaOMModule = panamaom(crossScalaVersion)
}

object lit extends Cross[Lit](v.scalaCrossVersions)
Expand All @@ -289,8 +298,8 @@ trait Lit
with Cross.Module[String] {
def scalaVersion: T[String] = crossValue
def runClasspath: T[Seq[os.Path]] = T(litutility(crossValue).runClasspath().map(_.path))
def pluginJars: T[Seq[os.Path]] = T(Seq(litutility(crossValue).circtPanamaBinderModule.pluginModule.jar().path))
def javaLibraryPath: T[Seq[os.Path]] = T(litutility(crossValue).circtPanamaBinderModule.libraryPaths().map(_.path))
def pluginJars: T[Seq[os.Path]] = T(Seq(litutility(crossValue).panamaConverterModule.pluginModule.jar().path))
def javaLibraryPath: T[Seq[os.Path]] = T(litutility(crossValue).panamaConverterModule.circtPanamaBindingModule.libraryPaths().map(_.path))
def javaHome: T[os.Path] = T(os.Path(sys.props("java.home")))
def chiselLitDir: T[os.Path] = T(millSourcePath)
def litConfigIn: T[PathRef] = T.source(millSourcePath / "tests" / "lit.site.cfg.py.in")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
78 changes: 61 additions & 17 deletions common.sc
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ trait HasJextractGeneratedSources
override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))
}

trait CIRCTPanamaBinderModule
extends ScalaModule
with HasJextractGeneratedSources
with HasChisel {
// Java Codegen for all declared functions.
// All of these functions are not private API which is subject to change.
trait CIRCTPanamaBindingModule
extends HasJextractGeneratedSources {

def includeConstants = T.input(os.read.lines(millSourcePath / "includeConstants.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def includeFunctions = T.input(os.read.lines(millSourcePath / "includeFunctions.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
Expand All @@ -197,28 +197,72 @@ trait CIRCTPanamaBinderModule
def includeVars = T.input(os.read.lines(millSourcePath / "includeVars.txt").filter(s => s.nonEmpty && !s.startsWith("#")))
def linkLibraries = T.input(os.read.lines(millSourcePath / "linkLibraries.txt").filter(s => s.nonEmpty && !s.startsWith("#")))

def target: T[String] = T("org.llvm.circt")
def headerClassName: T[String] = T("CAPI")
def target = T("org.llvm.circt")
def headerClassName = T("CAPI")
}

trait HasCIRCTPanamaBinderModule
extends ScalaModule
with HasChisel {
def circtPanamaBinderModule: CIRCTPanamaBinderModule

override def chiselModule = circtPanamaBinderModule.chiselModule

override def pluginModule = circtPanamaBinderModule.pluginModule
trait HasCIRCTPanamaBindingModule
extends JavaModule {
def circtPanamaBindingModule: CIRCTPanamaBindingModule

override def moduleDeps = super.moduleDeps ++ Some(circtPanamaBinderModule)
override def moduleDeps = super.moduleDeps ++ Some(circtPanamaBindingModule)

override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "20"))
override def javacOptions = T(super.javacOptions() ++ Seq("--enable-preview", "--release", "21"))

override def forkArgs: T[Seq[String]] = T(
super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview")
++ circtPanamaBinderModule
++ circtPanamaBindingModule
.libraryPaths()
.map(p => s"-Djava.library.path=${p.path}")
)
}

// The Scala API for PanamaBinding, API here is experimentally public to all developers
trait PanamaLibModule
extends ScalaModule
with HasCIRCTPanamaBindingModule

trait HasPanamaLibModule
extends ScalaModule
with HasCIRCTPanamaBindingModule {
def panamaLibModule: PanamaLibModule

def circtPanamaBindingModule = panamaLibModule.circtPanamaBindingModule

override def moduleDeps = super.moduleDeps ++ Some(panamaLibModule)
}

trait PanamaOMModule
extends ScalaModule
with HasPanamaLibModule

trait HasPanamaOMModule
extends ScalaModule
with HasCIRCTPanamaBindingModule {
def panamaOMModule: PanamaOMModule

def circtPanamaBindingModule = panamaOMModule.circtPanamaBindingModule

override def moduleDeps = super.moduleDeps ++ Some(panamaOMModule)
}

trait PanamaConverterModule
extends ScalaModule
with HasPanamaOMModule
with HasChisel

trait HasPanamaConverterModule
extends ScalaModule
with HasCIRCTPanamaBindingModule
with HasChisel {
def panamaConverterModule: PanamaConverterModule

def circtPanamaBindingModule = panamaConverterModule.circtPanamaBindingModule

override def chiselModule = panamaConverterModule.chiselModule

override def pluginModule = panamaConverterModule.pluginModule

override def moduleDeps = super.moduleDeps ++ Some(panamaConverterModule)
}

1 change: 1 addition & 0 deletions core/src/main/scala/chisel3/internal/CIRCTConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import chisel3.assume.Assume
import chisel3.cover.Cover
import chisel3.internal.firrtl.ir._

@deprecated("There no CIRCTConverter anymore, use circtpanamaconverter directly", "Chisel 6.0")
abstract class CIRCTConverter {
val mlirStream: Writable
val firrtlStream: Writable
Expand Down
Loading

0 comments on commit b37180d

Please sign in to comment.