Skip to content

Commit

Permalink
[om] add entries decoderInstructionsJson{,Pretty}
Browse files Browse the repository at this point in the history
  • Loading branch information
SpriteOvO committed Jun 24, 2024
1 parent 67110a2 commit 764e7ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
10 changes: 10 additions & 0 deletions omreader/src/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ object Main {
println(simplyGetT1Reader(mlirbcFile).dlen)
}

@main
def decoderInstructionsJson(@arg(name = "mlirbc-file") mlirbcFile: os.Path) = {
println(simplyGetT1Reader(mlirbcFile).decoderInstructionsJson)
}

@main
def decoderInstructionsJsonPretty(@arg(name = "mlirbc-file") mlirbcFile: os.Path) = {
println(simplyGetT1Reader(mlirbcFile).decoderInstructionsJsonPretty)
}

def simplyGetT1Reader(mlirbcFile: os.Path) = OMReader.fromFile(mlirbcFile).t1Reader

def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
Expand Down
33 changes: 32 additions & 1 deletion omreaderlib/src/Interface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ class T1Reader private[omreaderlib](evaluator: PanamaCIRCTOMEvaluator, basePath:

def vlen: Long = t1.field("vlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer
def dlen: Long = t1.field("dlen").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveInteger].integer
private def decoderInstructionsJsonImpl: ujson.Value = {
val decoder = t1.field("decoder").asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
val instructions = decoder.field("instructions").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]

instructions.elements.map(instruction => {
val instr = instruction.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
val attributes = instr.field("attributes").asInstanceOf[PanamaCIRCTOMEvaluatorValueList]

ujson.Obj(
"attributes" -> attributes.elements.map(attribute => {
val attr = attribute.asInstanceOf[PanamaCIRCTOMEvaluatorValueObject]
val description = attr.field("description").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
val identifier = attr.field("identifier").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
val value = attr.field("value").asInstanceOf[PanamaCIRCTOMEvaluatorValuePrimitiveString].toString
ujson.Obj(
"description" -> description,
"identifier" -> identifier,
"value" -> value
)
})
)
})
}
def decoderInstructionsJson: String = ujson.write(decoderInstructionsJsonImpl)
def decoderInstructionsJsonPretty: String = ujson.write(decoderInstructionsJsonImpl, 2)

def dumpMethods(): Unit = {
val mirror = runtimeMirror(getClass.getClassLoader).reflect(this)
Expand All @@ -52,7 +77,13 @@ class T1Reader private[omreaderlib](evaluator: PanamaCIRCTOMEvaluator, basePath:
)
methods.foreach(method => {
if (!method.name.toString.startsWith("dump")) {
val value = mirror.reflectMethod(method.asMethod)()
var value = mirror.reflectMethod(method.asMethod)().toString.replace("\n", "\\n")

val displayLength = 100
if (value.length > displayLength) {
value = value.take(displayLength) + s" ... ${value.length - displayLength} characters"
}

println(s"${method.name} = $value")
}
})
Expand Down

0 comments on commit 764e7ff

Please sign in to comment.