Skip to content

Commit

Permalink
[om] add omreader tool
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO authored and sequencer committed Apr 18, 2024
1 parent 56affb7 commit d521b5c
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 2 deletions.
18 changes: 18 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions common.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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"}")
)
}
2 changes: 2 additions & 0 deletions nix/t1/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 { };
Expand Down Expand Up @@ -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; };
Expand Down
25 changes: 25 additions & 0 deletions nix/t1/om.nix
Original file line number Diff line number Diff line change
@@ -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.";
}
8 changes: 6 additions & 2 deletions nix/t1/t1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let
./../../ipemu/src
./../../elaborator
./../../configgen
./../../omreader
];
};

Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions omreader/src/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

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)
}

0 comments on commit d521b5c

Please sign in to comment.