diff --git a/omreader/src/Main.scala b/omreader/src/Main.scala index bce1341d5e..0f36cdae7f 100644 --- a/omreader/src/Main.scala +++ b/omreader/src/Main.scala @@ -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 @@ -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()) @@ -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) + } + } + } +} +