From d521b5cf70f465bbbac417f2ba08417bc614f1d3 Mon Sep 17 00:00:00 2001 From: Asuna Date: Thu, 14 Mar 2024 07:25:36 +0100 Subject: [PATCH] [om] add omreader tool --- build.sc | 18 ++++++++++++++++++ common.sc | 14 ++++++++++++++ nix/t1/default.nix | 2 ++ nix/t1/om.nix | 25 +++++++++++++++++++++++++ nix/t1/t1.nix | 8 ++++++-- omreader/src/Main.scala | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 nix/t1/om.nix create mode 100644 omreader/src/Main.scala diff --git a/build.sc b/build.sc index baad75837..ff5c30ba4 100644 --- a/build.sc +++ b/build.sc @@ -281,6 +281,24 @@ trait Elaborator } +object omreader extends OMReader + +trait OMReader + extends millbuild.common.OMReaderModule { + def scalaVersion = T(v.scala) + + def panamaconverterModule = panamaconverter + + def circtInstallPath = T.input(PathRef(os.Path(T.ctx().env("CIRCT_INSTALL_PATH")))) + + def mainargsIvy = v.mainargs + + def chiselModule = Some(chisel) + def chiselPluginJar = T(Some(chisel.pluginModule.jar())) + def chiselPluginIvy = None + def chiselIvy = None +} + /** A simple release flow for T1 generator: * package required dependency to flat jar. * usage: diff --git a/common.sc b/common.sc index 56350ff93..44ee74b20 100644 --- a/common.sc +++ b/common.sc @@ -129,3 +129,17 @@ trait ElaboratorModule super.forkArgs() ++ Seq("--enable-native-access=ALL-UNNAMED", "--enable-preview", s"-Djava.library.path=${ circtInstallPath().path / "lib"}") ) } + +trait OMReaderModule + extends ScalaModule + with HasChisel { + def panamaconverterModule: ScalaModule + def circtInstallPath: T[PathRef] + override def moduleDeps = super.moduleDeps ++ Seq(panamaconverterModule) + def mainargsIvy: Dep + override def ivyDeps = T(super.ivyDeps() ++ Seq(mainargsIvy)) + 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", s"-Djava.library.path=${ circtInstallPath().path / "lib"}") + ) +} diff --git a/nix/t1/default.nix b/nix/t1/default.nix index e720595ec..6be4711aa 100644 --- a/nix/t1/default.nix +++ b/nix/t1/default.nix @@ -25,6 +25,7 @@ lib.makeScope newScope elaborator = _millOutput.elaborator // { meta.mainProgram = "elaborator"; }; configgen = _millOutput.configgen // { meta.mainProgram = "configgen"; }; + omreader = _millOutput.omreader // { meta.mainProgram = "omreader"; }; t1package = _millOutput.t1package; submodules = self.callPackage ./submodules.nix { }; @@ -70,6 +71,7 @@ lib.makeScope newScope mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "ip"; /* use-binder = true; */ }; rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.ip.mlirbc; }; + om = innerSelf.callPackage ./om.nix { mlirbc = innerSelf.ip.mlirbc; }; emu-mlirbc = innerSelf.callPackage ./mlirbc.nix { target = "ipemu"; /* use-binder = true; */ }; emu-rtl = innerSelf.callPackage ./rtl.nix { mlirbc = innerSelf.ip.emu-mlirbc; }; diff --git a/nix/t1/om.nix b/nix/t1/om.nix new file mode 100644 index 000000000..8c4361df5 --- /dev/null +++ b/nix/t1/om.nix @@ -0,0 +1,25 @@ +{ stdenvNoCC +, lib + +, omreader +, circt +, mlirbc +}: + +let + omReaderArgs = lib.filter (s: s != "") [ + "--mlirbc-file" + "${mlirbc}/${mlirbc.elaborateTarget}-${mlirbc.elaborateConfig}.mlirbc" + ]; +in +stdenvNoCC.mkDerivation { + name = "t1-${mlirbc.elaborateConfig}-${mlirbc.elaborateTarget}-om"; + + nativeBuildInputs = [ circt ]; + + buildCommand = '' + ${omreader}/bin/omreader ${lib.escapeShellArgs omReaderArgs} + ''; + + meta.description = "TODO."; +} diff --git a/nix/t1/t1.nix b/nix/t1/t1.nix index 5b1d7e069..38db905fa 100644 --- a/nix/t1/t1.nix +++ b/nix/t1/t1.nix @@ -30,6 +30,7 @@ let ./../../ipemu/src ./../../elaborator ./../../configgen + ./../../omreader ]; }; @@ -71,7 +72,7 @@ let env.CIRCT_INSTALL_PATH = circt-full; - outputs = [ "out" "configgen" "elaborator" "t1package" ]; + outputs = [ "out" "configgen" "elaborator" "t1package" "omreader" ]; buildPhase = '' mill -i '__.assembly' @@ -85,21 +86,24 @@ let strip-nondeterminism out/elaborator/assembly.dest/out.jar strip-nondeterminism out/configgen/assembly.dest/out.jar + strip-nondeterminism out/omreader/assembly.dest/out.jar strip-nondeterminism out/t1package/assembly.dest/out.jar strip-nondeterminism out/t1package/sourceJar.dest/out.jar strip-nondeterminism out/t1package/chiselPluginJar.dest/out.jar mv out/configgen/assembly.dest/out.jar $out/share/java/configgen.jar mv out/elaborator/assembly.dest/out.jar $out/share/java/elaborator.jar + mv out/omreader/assembly.dest/out.jar $out/share/java/omreader.jar mkdir -p $t1package/share/java mv out/t1package/sourceJar.dest/out.jar $t1package/share/java/t1package-sources.jar mv out/t1package/assembly.dest/out.jar $t1package/share/java/t1package.jar mv out/t1package/chiselPluginJar.dest/out.jar $t1package/share/java/chiselPluginJar.jar - mkdir -p $configgen/bin $elaborator/bin + mkdir -p $configgen/bin $elaborator/bin $omreader/bin makeWrapper ${jdk21}/bin/java $configgen/bin/configgen --add-flags "-jar $out/share/java/configgen.jar" makeWrapper ${jdk21}/bin/java $elaborator/bin/elaborator --add-flags "--enable-preview -Djava.library.path=${circt-full}/lib -jar $out/share/java/elaborator.jar" + makeWrapper ${jdk21}/bin/java $omreader/bin/omreader --add-flags "--enable-preview -Djava.library.path=${circt-full}/lib -jar $out/share/java/omreader.jar" ''; }; in diff --git a/omreader/src/Main.scala b/omreader/src/Main.scala new file mode 100644 index 000000000..595b928e7 --- /dev/null +++ b/omreader/src/Main.scala @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 Jiuyang Liu + +package org.chipsalliance.t1.omreader + +import mainargs._ +import chisel3.panamalib.option._ +import chisel3.panamaconverter.PanamaCIRCTConverter + +object Main { + implicit object PathRead extends TokensReader.Simple[os.Path] { + def shortName = "path" + def read(strs: Seq[String]): Either[String, os.Path] = Right(os.Path(strs.head, os.pwd)) + } + + @main + def run( + @arg(name = "mlirbc-file") mlirbc: os.Path, + ) = { + val cvt = PanamaCIRCTConverter.newWithMlirBc(os.read.bytes(mlirbc)) + + val pm = cvt.passManager() + assert(pm.populatePreprocessTransforms()) + assert(pm.populateCHIRRTLToLowFIRRTL()) + assert(pm.populateLowFIRRTLToHW()) + assert(pm.populateLowHWToSV()) + assert(pm.populateExportVerilog(_ => ())) + assert(pm.populateFinalizeIR()) + assert(pm.run()) + + val om = cvt.om() + val evaluator = om.evaluator() + val t1 = evaluator.instantiate("T1_1_Class", Seq(om.newBasePathEmpty)) + t1.foreachField((name, value) => println(s".$name => { ${value.toString} }")) + } + + def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) +}