Skip to content

Commit

Permalink
[om] refactor the omreader API
Browse files Browse the repository at this point in the history
  • Loading branch information
sequencer committed Oct 13, 2024
1 parent 05360fa commit d5b9070
Show file tree
Hide file tree
Showing 9 changed files with 486 additions and 187 deletions.
85 changes: 0 additions & 85 deletions omreader/src/Main.scala

This file was deleted.

45 changes: 45 additions & 0 deletions omreader/src/t1/T1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.omreader.t1

import mainargs._
import org.chipsalliance.t1.omreaderlib.t1.T1

object T1 {
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 vlen(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
println(new T1(os.read.bytes(mlirbcFile)).vlen)

@main
def dlen(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
println(new T1(os.read.bytes(mlirbcFile)).dlen)

@main
def instructions(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
new T1(os.read.bytes(mlirbcFile)).instructions.foreach(println)

@main
def extensions(
@arg(name = "mlirbc-file") mlirbcFile: os.Path
) =
println(new T1(os.read.bytes(mlirbcFile)).extensions.mkString(""))

@main
def march(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
println(new T1(os.read.bytes(mlirbcFile)).march)

@main
def sram(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
new T1(os.read.bytes(mlirbcFile)).sram.foreach(s => println(upickle.default.write(s)))

@main
def retime(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
new T1(os.read.bytes(mlirbcFile)).retime.foreach(r => println(upickle.default.write(r)))

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
}
45 changes: 45 additions & 0 deletions omreader/src/t1rocketv/T1RocketTile.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.omreader.t1rocketv

import mainargs._
import org.chipsalliance.t1.omreaderlib.t1rocketv.T1RocketTile

object T1RocketTile {
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 vlen(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
println(new T1RocketTile(os.read.bytes(mlirbcFile)).vlen)

@main
def dlen(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
println(new T1RocketTile(os.read.bytes(mlirbcFile)).dlen)

@main
def instructions(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
new T1RocketTile(os.read.bytes(mlirbcFile)).instructions.foreach(println)

@main
def extensions(
@arg(name = "mlirbc-file") mlirbcFile: os.Path
) =
println(new T1RocketTile(os.read.bytes(mlirbcFile)).extensions.mkString(""))

@main
def march(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
println(new T1RocketTile(os.read.bytes(mlirbcFile)).march)

@main
def sram(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
new T1RocketTile(os.read.bytes(mlirbcFile)).sram.foreach(s => println(upickle.default.write(s)))

@main
def retime(@arg(name = "mlirbc-file") mlirbcFile: os.Path) =
new T1RocketTile(os.read.bytes(mlirbcFile)).retime.foreach(r => println(upickle.default.write(r)))

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
}
102 changes: 0 additions & 102 deletions omreaderlib/src/Interface.scala

This file was deleted.

17 changes: 17 additions & 0 deletions omreaderlib/src/OMReader.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]>

package org.chipsalliance.t1.omreaderlib

import chisel3.panamaconverter.PanamaCIRCTConverter
import chisel3.panamaom._

trait OMReader {
val mlirbc: Array[Byte]
val top: String
protected lazy val cvt: PanamaCIRCTConverter = PanamaCIRCTConverter.newWithMlirBc(mlirbc)
protected lazy val om: PanamaCIRCTOM = cvt.om()
protected lazy val evaluator: PanamaCIRCTOMEvaluator = om.evaluator()
protected lazy val basePath: PanamaCIRCTOMEvaluatorValueBasePath = om.newBasePathEmpty()
protected lazy val entry: PanamaCIRCTOMEvaluatorValueObject = evaluator.instantiate(top, Seq(basePath)).get
}
Loading

0 comments on commit d5b9070

Please sign in to comment.