-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2022 Jiuyang Liu <[email protected]> | ||
|
||
package org.chipsalliance.t1.omreader | ||
|
||
import java.io.BufferedInputStream | ||
import mainargs._ | ||
import chisel3.panamaom._ | ||
import org.chipsalliance.t1.omreaderlib._ | ||
|
||
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") mlirbcFile: Option[os.Path], | ||
@arg(name = "class-name") className: String, | ||
@arg(name = "dump-methods") dumpMethods: Flag, | ||
@arg(name = "eval") eval: Option[String], | ||
) = { | ||
val omReader = mlirbcFile match { | ||
case Some(path) => OMReader.fromFile(path, className) | ||
case None => | ||
val stdin = new BufferedInputStream(System.in) | ||
val bytes = Stream.continually(stdin.read).takeWhile(_ != -1).map(_.toByte).toArray | ||
OMReader.fromBytes(bytes, className) | ||
} | ||
val t1Reader = omReader.t1Reader | ||
|
||
if (eval.nonEmpty) { | ||
println(SimpleInputEval(omReader.entryUnderlying, eval.get)) | ||
} else if (dumpMethods.value) { | ||
t1Reader.dumpMethods() | ||
} else { | ||
t1Reader.dumpAll() | ||
} | ||
} | ||
|
||
@main | ||
def vlen(@arg(name = "mlirbc-file") mlirbcFile: os.Path) = { | ||
println(simplyGetT1Reader(mlirbcFile).vlen) | ||
} | ||
|
||
@main | ||
def dlen(@arg(name = "mlirbc-file") mlirbcFile: os.Path) = { | ||
println(simplyGetT1Reader(mlirbcFile).dlen) | ||
} | ||
|
||
def simplyGetT1Reader(mlirbcFile: os.Path) = OMReader.fromFile(mlirbcFile, "T1Subsystem_Class").t1Reader | ||
|
||
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.chipsalliance.t1.omreaderlib | ||
|
||
import scala.reflect.runtime.universe._ | ||
import chisel3.panamalib.option._ | ||
import chisel3.panamaom._ | ||
import chisel3.panamaconverter.PanamaCIRCTConverter | ||
|
||
object OMReader { | ||
def fromFile(mlirbcFile: os.Path, className: String): OMReader = { | ||
new OMReader(os.read.bytes(mlirbcFile), className) | ||
} | ||
|
||
def fromBytes(mlirbc: Array[Byte], className: String): OMReader = { | ||
new OMReader(mlirbc, className) | ||
} | ||
} | ||
|
||
class OMReader private(mlirbc: Array[Byte], className: String) { | ||
private val cvt = PanamaCIRCTConverter.newWithMlirBc(mlirbc) | ||
|
||
private 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()) | ||
|
||
private val om = cvt.om() | ||
private val evaluator = om.evaluator() | ||
private val entry = evaluator.instantiate(className, Seq(om.newBasePathEmpty)) | ||
|
||
def entryUnderlying: PanamaCIRCTOMEvaluatorValueObject = entry | ||
def t1Reader: T1Reader = new T1Reader(entry) | ||
} | ||
|
||
class T1Reader private[omreaderlib](entry: PanamaCIRCTOMEvaluatorValueObject) { | ||
private val om = entry.field("om").asInstanceOf[PanamaCIRCTOMEvaluatorValueObject] | ||
private val t1 = om.field("t1").asInstanceOf[PanamaCIRCTOMEvaluatorValueObject] | ||
|
||
def vlen: Long = t1.field("vlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer | ||
def dlen: Long = t1.field("dlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer | ||
|
||
def dumpMethods(): Unit = { | ||
val mirror = runtimeMirror(getClass.getClassLoader).reflect(this) | ||
val methods = typeOf[T1Reader].decls.toList.filter( | ||
m => m.isPublic && m.isMethod && !m.isConstructor && !m.asMethod.isGetter | ||
) | ||
methods.foreach(method => { | ||
if (!method.name.toString.startsWith("dump")) { | ||
val value = mirror.reflectMethod(method.asMethod)() | ||
println(s"${method.name} = $value") | ||
} | ||
}) | ||
} | ||
|
||
def dumpAll(): Unit = { | ||
entry.foreachField((name, value) => println(s".$name => $value")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters