Skip to content

Commit

Permalink
WIP: omreader improvements and introduce omreaderlib
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO authored and Avimitin committed Apr 24, 2024
1 parent ca46cbd commit 0277c84
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions omreader/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

package org.chipsalliance.t1.omreader

import java.io.BufferedInputStream

import mainargs._
import chisel3.panamalib.option._
import chisel3.panamaom._
import chisel3.panamaconverter.PanamaCIRCTConverter
import org.chipsalliance.t1.omreaderlib

Expand All @@ -16,11 +19,20 @@ object Main {

@main
def run(
@arg(name = "mlirbc-file") mlirbc: os.Path,
@arg(name = "mlirbc-file") mlirbcFile: Option[os.Path],
@arg(name = "class-name") className: String,
@arg(name = "dump") dump: Flag,
@arg(name = "eval") eval: Option[String],
) = {
omreaderlib.Hello()

val cvt = PanamaCIRCTConverter.newWithMlirBc(os.read.bytes(mlirbc))
val inputs = mlirbcFile match {
case Some(path) => os.read.bytes(path)
case None =>
val stdin = new BufferedInputStream(System.in)
Stream.continually(stdin.read).takeWhile(_ != -1).map(_.toByte).toArray
}
val cvt = PanamaCIRCTConverter.newWithMlirBc(inputs)

val pm = cvt.passManager()
assert(pm.populatePreprocessTransforms())
Expand All @@ -33,9 +45,30 @@ object Main {

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} }"))
val entry = evaluator.instantiate(className, Seq(om.newBasePathEmpty))

if (dump.value) {
entry.foreachField((name, value) => println(s".$name => $value"))
}
else if (eval.nonEmpty) {
val result = SimpleInputEval(entry, eval.get)
println(result)
}
}

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
}

object SimpleInputEval {
def apply(entry: PanamaCIRCTOMEvaluatorValue, input: String): PanamaCIRCTOMEvaluatorValue = {
input.split("\\.").foldLeft(entry) {
case (obj, field) =>
if (field.forall(_.isDigit)) {
obj.asInstanceOf[PanamaCIRCTOMEvaluatorValueList].getElement(field.toLong)
} else {
obj.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject].field(field)
}
}
}
}

0 comments on commit 0277c84

Please sign in to comment.