From ac63917f4d6d22170db690542b55d636fbda608d Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 7 Oct 2015 15:31:16 -0700 Subject: Added utility map functions Stmt -> Stmt, S; Exp -> Exp, S; Exp -> Exp, E --- src/main/scala/firrtl/Utils.scala | 46 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'src/main/scala/firrtl/Utils.scala') diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 916408bc..37cdcc71 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -2,14 +2,16 @@ /* TODO * - Adopt style more similar to Chisel3 Emitter? + * - Find way to have generic map function instead of mapE and mapS under Stmt implicits */ package firrtl import scala.collection.mutable.StringBuilder +import scala.reflect.runtime.universe._ object Utils { - + implicit class BigIntUtils(bi: BigInt){ def serialize(): String = "\"h0" + bi.toString(16) + "\"" @@ -68,6 +70,14 @@ object Utils { case p: DoPrimOp => s"${p.op.serialize}(" + (p.args.map(_.serialize) ++ p.consts.map(_.toString)).mkString(", ") + ")" } + + def map(f: Exp => Exp): Exp = + exp match { + case s: Subfield => Subfield(f(s.exp), s.name, s.tpe) + case s: Subindex => Subindex(f(s.exp), s.value) + case p: DoPrimOp => DoPrimOp(p.op, p.args.map(f), p.consts) + case e: Exp => e + } } // AccessorDir @@ -81,6 +91,36 @@ object Utils { } } + // Some Scala implicit magic to solve type erasure on Stmt map function overloading + private trait StmtMagnet { + def map(stmt: Stmt): Stmt + } + private object StmtMagnet { + implicit def forStmt(f: Stmt => Stmt) = new StmtMagnet { + override def map(stmt: Stmt): Stmt = + stmt match { + case w: When => When(w.info, w.pred, f(w.conseq), f(w.alt)) + case b: Block => Block(b.stmts.map(f)) + case s: Stmt => s + } + } + implicit def forExp(f: Exp => Exp) = new StmtMagnet { + override def map(stmt: Stmt): Stmt = + stmt match { + case r: DefReg => DefReg(r.info, r.name, r.tpe, f(r.clock), f(r.reset)) + case m: DefMemory => DefMemory(m.info, m.name, m.seq, m.tpe, f(m.clock)) + case i: DefInst => DefInst(i.info, i.name, f(i.module)) + case n: DefNode => DefNode(n.info, n.name, f(n.value)) + case a: DefAccessor => DefAccessor(a.info, a.name, a.dir, f(a.source), f(a.index)) + case o: OnReset => OnReset(o.info, f(o.lhs), f(o.rhs)) + case c: Connect => Connect(c.info, f(c.lhs), f(c.rhs)) + case b: BulkConnect => BulkConnect(b.info, f(b.lhs), f(b.rhs)) + case w: When => When(w.info, f(w.pred), w.conseq, w.alt) + case a: Assert => Assert(a.info, f(a.pred)) + case s: Stmt => s + } + } + } implicit class StmtUtils(stmt: Stmt) { def serialize(): String = @@ -114,6 +154,10 @@ object Utils { case a: Assert => s"assert ${a.pred.serialize}" case EmptyStmt => "skip" } + + // Using implicit types to allow overloading of function type to map, see StmtMagnet above + def map[T](f: T => T)(implicit magnet: (T => T) => StmtMagnet): Stmt = magnet(f).map(stmt) + } implicit class WidthUtils(w: Width) { -- cgit v1.2.3 From 0c288c48382f1b31fbfb1c202867fb444e46136c Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 12 Oct 2015 16:45:21 -0700 Subject: Added support for no width to mean unknown, and print nothing instead of for unknown width. Also added test to check this --- src/main/scala/firrtl/Utils.scala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/main/scala/firrtl/Utils.scala') diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 37cdcc71..8a7a5b0d 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -62,8 +62,8 @@ object Utils { implicit class ExpUtils(exp: Exp) { def serialize(): String = exp match { - case v: UIntValue => s"UInt<${v.width}>(${v.value.serialize})" - case v: SIntValue => s"SInt<${v.width}>(${v.value.serialize})" + case v: UIntValue => s"UInt${v.width.serialize}(${v.value.serialize})" + case v: SIntValue => s"SInt${v.width.serialize}(${v.value.serialize})" case r: Ref => r.name case s: Subfield => s"${s.exp.serialize}.${s.name}" case s: Subindex => s"${s.exp.serialize}[${s.value}]" @@ -163,8 +163,8 @@ object Utils { implicit class WidthUtils(w: Width) { def serialize(): String = w match { - case UnknownWidth => "?" - case w: IntWidth => w.width.toString + case UnknownWidth => "" + case w: IntWidth => s"<${w.width.toString}>" } } @@ -187,8 +187,8 @@ object Utils { t match { case ClockType => "Clock" case UnknownType => "UnknownType" - case t: UIntType => s"UInt<${t.width.serialize}>" - case t: SIntType => s"SInt<${t.width.serialize}>" + case t: UIntType => s"UInt${t.width.serialize}" + case t: SIntType => s"SInt${t.width.serialize}" case t: BundleType => s"{ ${t.fields.map(_.serialize).mkString(commas)} }" case t: VectorType => s"${t.tpe.serialize}[${t.size}]" } -- cgit v1.2.3 From 09ef2e42b00174e99124477b443a472e8664708f Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 12 Oct 2015 16:56:08 -0700 Subject: Renamed Subindex to Index and added type information to Index and DoPrimOp --- src/main/scala/firrtl/Utils.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/scala/firrtl/Utils.scala') diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 8a7a5b0d..110da9a5 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -66,7 +66,7 @@ object Utils { case v: SIntValue => s"SInt${v.width.serialize}(${v.value.serialize})" case r: Ref => r.name case s: Subfield => s"${s.exp.serialize}.${s.name}" - case s: Subindex => s"${s.exp.serialize}[${s.value}]" + case s: Index => s"${s.exp.serialize}[${s.value}]" case p: DoPrimOp => s"${p.op.serialize}(" + (p.args.map(_.serialize) ++ p.consts.map(_.toString)).mkString(", ") + ")" } @@ -74,8 +74,8 @@ object Utils { def map(f: Exp => Exp): Exp = exp match { case s: Subfield => Subfield(f(s.exp), s.name, s.tpe) - case s: Subindex => Subindex(f(s.exp), s.value) - case p: DoPrimOp => DoPrimOp(p.op, p.args.map(f), p.consts) + case i: Index => Index(f(i.exp), i.value, i.tpe) + case p: DoPrimOp => DoPrimOp(p.op, p.args.map(f), p.consts, p.tpe) case e: Exp => e } } -- cgit v1.2.3 From bf4488870e1def4d76297dd8fdd795a82bc4ded3 Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 12 Oct 2015 17:38:12 -0700 Subject: Added initial support for debug printing for lit based testing, most types of printVars still missing. Added Logger class for debug printing --- src/main/scala/firrtl/Utils.scala | 135 ++++++++++++++++++++++++++++++-------- 1 file changed, 108 insertions(+), 27 deletions(-) (limited to 'src/main/scala/firrtl/Utils.scala') diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 110da9a5..b50bd7b5 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -8,17 +8,47 @@ package firrtl import scala.collection.mutable.StringBuilder -import scala.reflect.runtime.universe._ +//import scala.reflect.runtime.universe._ object Utils { + // Is there a more elegant way to do this? + private type FlagMap = Map[Symbol, Boolean] + private val FlagMap = Map[Symbol, Boolean]().withDefaultValue(false) + + def debug(node: AST)(implicit flags: FlagMap): String = { + if (!flags.isEmpty) { + var str = "" + if (flags('types)) { + val tpe = node.getType + if( tpe.nonEmpty ) str += s"@" + } + str + } + else { + "" + } + } + implicit class BigIntUtils(bi: BigInt){ - def serialize(): String = + def serialize(implicit flags: FlagMap = FlagMap): String = "\"h0" + bi.toString(16) + "\"" } + implicit class ASTUtils(ast: AST) { + def getType(): Option[Type] = + ast match { + case e: Exp => e.getType + case s: Stmt => s.getType + case f: Field => f.getType + case t: Type => t.getType + case p: Port => p.getType + case _ => None + } + } + implicit class PrimOpUtils(op: PrimOp) { - def serialize(): String = { + def serialize(implicit flags: FlagMap = FlagMap): String = { op match { case Add => "add" case Sub => "sub" @@ -60,8 +90,8 @@ object Utils { } implicit class ExpUtils(exp: Exp) { - def serialize(): String = - exp match { + def serialize(implicit flags: FlagMap = FlagMap): String = { + val ret = exp match { case v: UIntValue => s"UInt${v.width.serialize}(${v.value.serialize})" case v: SIntValue => s"SInt${v.width.serialize}(${v.value.serialize})" case r: Ref => r.name @@ -70,6 +100,8 @@ object Utils { case p: DoPrimOp => s"${p.op.serialize}(" + (p.args.map(_.serialize) ++ p.consts.map(_.toString)).mkString(", ") + ")" } + ret + debug(exp) + } def map(f: Exp => Exp): Exp = exp match { @@ -78,11 +110,23 @@ object Utils { case p: DoPrimOp => DoPrimOp(p.op, p.args.map(f), p.consts, p.tpe) case e: Exp => e } + + def getType(): Option[Type] = { + exp match { + case v: UIntValue => Option(UIntType(UnknownWidth)) + case v: SIntValue => Option(SIntType(UnknownWidth)) + case r: Ref => Option(r.tpe) + case s: Subfield => Option(s.tpe) + case i: Index => Option(i.tpe) + case p: DoPrimOp => Option(p.tpe) + case e: Exp => None + } + } } // AccessorDir implicit class AccessorDirUtils(dir: AccessorDir) { - def serialize(): String = + def serialize(implicit flags: FlagMap = FlagMap): String = dir match { case Infer => "infer" case Read => "read" @@ -123,8 +167,9 @@ object Utils { } implicit class StmtUtils(stmt: Stmt) { - def serialize(): String = - stmt match { + def serialize(implicit flags: FlagMap = FlagMap): String = + { + var ret = stmt match { case w: DefWire => s"wire ${w.name} : ${w.tpe.serialize}" case r: DefReg => s"reg ${r.name} : ${r.tpe.serialize}, ${r.clock.serialize}, ${r.reset.serialize}" case m: DefMemory => (if(m.seq) "smem" else "cmem") + @@ -149,82 +194,118 @@ object Utils { case b: Block => { val s = new StringBuilder b.stmts.foreach { s ++= newline ++ _.serialize } - s.result - } + s.result + debug(b) + } case a: Assert => s"assert ${a.pred.serialize}" case EmptyStmt => "skip" } + ret + debug(stmt) + } // Using implicit types to allow overloading of function type to map, see StmtMagnet above def map[T](f: T => T)(implicit magnet: (T => T) => StmtMagnet): Stmt = magnet(f).map(stmt) + def getType(): Option[Type] = + stmt match { + case w: DefWire => Option(w.tpe) + case r: DefReg => Option(r.tpe) + case m: DefMemory => Option(m.tpe) + case p: DefPoison => Option(p.tpe) + case s: Stmt => None + } } implicit class WidthUtils(w: Width) { - def serialize(): String = - w match { - case UnknownWidth => "" + def serialize(implicit flags: FlagMap = FlagMap): String = { + val s = w match { + case UnknownWidth => "" //"?" case w: IntWidth => s"<${w.width.toString}>" } + s + debug(w) + } } implicit class FieldDirUtils(dir: FieldDir) { - def serialize(): String = - dir match { + def serialize(implicit flags: FlagMap = FlagMap): String = { + val s = dir match { case Reverse => "flip " case Default => "" } + s + debug(dir) + } } implicit class FieldUtils(field: Field) { - def serialize(): String = - s"${field.dir.serialize} ${field.name} : ${field.tpe.serialize}" + def serialize(implicit flags: FlagMap = FlagMap): String = + s"${field.dir.serialize} ${field.name} : ${field.tpe.serialize}" + debug(field) + + def getType(): Option[Type] = Option(field.tpe) } implicit class TypeUtils(t: Type) { - def serialize(): String = { + def serialize(implicit flags: FlagMap = FlagMap): String = { val commas = ", " // for mkString in BundleType - t match { + val s = t match { case ClockType => "Clock" - case UnknownType => "UnknownType" + //case UnknownType => "UnknownType" + case UnknownType => "?" case t: UIntType => s"UInt${t.width.serialize}" case t: SIntType => s"SInt${t.width.serialize}" case t: BundleType => s"{ ${t.fields.map(_.serialize).mkString(commas)} }" case t: VectorType => s"${t.tpe.serialize}[${t.size}]" } + s + debug(t) } + + // TODO how does this work? + def getType(): Option[Type] = + t match { + case v: VectorType => Option(v.tpe) + case tpe: Type => None + } + + def wipeWidth(): Type = + t match { + case t: UIntType => UIntType(UnknownWidth) + case t: SIntType => SIntType(UnknownWidth) + case _ => t + } } implicit class PortDirUtils(p: PortDir) { - def serialize(): String = - p match { + def serialize(implicit flags: FlagMap = FlagMap): String = { + val s = p match { case Input => "input" case Output => "output" } + s + debug(p) + } } implicit class PortUtils(p: Port) { - def serialize(): String = - s"${p.dir.serialize} ${p.name} : ${p.tpe.serialize}" + def serialize(implicit flags: FlagMap = FlagMap): String = + s"${p.dir.serialize} ${p.name} : ${p.tpe.serialize}" + debug(p) + def getType(): Option[Type] = Option(p.tpe) } implicit class ModuleUtils(m: Module) { - def serialize(): String = { + def serialize(implicit flags: FlagMap = FlagMap): String = { var s = new StringBuilder(s"module ${m.name} : ") withIndent { s ++= m.ports.map(newline ++ _.serialize).mkString s ++= newline ++ m.stmt.serialize } + s ++= debug(m) s.toString } } implicit class CircuitUtils(c: Circuit) { - def serialize(): String = { + def serialize(implicit flags: FlagMap = FlagMap): String = { var s = new StringBuilder(s"circuit ${c.name} : ") - //withIndent { c.modules.foreach(s ++= newline ++ newline ++ _.serialize) } withIndent { s ++= newline ++ c.modules.map(_.serialize).mkString(newline + newline) } s ++= newline ++ newline + s ++= debug(c) s.toString } } -- cgit v1.2.3 From 9b737de6551e7446dfd92d86cd009b4b2f95c980 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Oct 2015 13:53:22 -0700 Subject: Moved Logger to new private object DebugUtils, changed UInt/SInt value printing to match stanza implementation --- src/main/scala/firrtl/Utils.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/scala/firrtl/Utils.scala') diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index b50bd7b5..8e9889b9 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -32,7 +32,7 @@ object Utils { implicit class BigIntUtils(bi: BigInt){ def serialize(implicit flags: FlagMap = FlagMap): String = - "\"h0" + bi.toString(16) + "\"" + "\"h" + bi.toString(16) + "\"" } implicit class ASTUtils(ast: AST) { -- cgit v1.2.3 From edd57efbadf493b331e69c8686662500fe859372 Mon Sep 17 00:00:00 2001 From: Jack Date: Wed, 14 Oct 2015 14:04:33 -0700 Subject: Modified getType to return Type rather than Option[Type] which makes more sense for some applications, also fixed up printing to better match stanza implementation --- src/main/scala/firrtl/Utils.scala | 55 +++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'src/main/scala/firrtl/Utils.scala') diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 8e9889b9..0cf19f04 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -21,7 +21,8 @@ object Utils { var str = "" if (flags('types)) { val tpe = node.getType - if( tpe.nonEmpty ) str += s"@" + //if( tpe != UnknownType ) str += s"@" + str += s"@" } str } @@ -36,15 +37,17 @@ object Utils { } implicit class ASTUtils(ast: AST) { - def getType(): Option[Type] = + def getType(): Type = ast match { case e: Exp => e.getType case s: Stmt => s.getType - case f: Field => f.getType + //case f: Field => f.getType case t: Type => t.getType case p: Port => p.getType - case _ => None + case _ => UnknownType } + + //def foreach } implicit class PrimOpUtils(op: PrimOp) { @@ -111,15 +114,14 @@ object Utils { case e: Exp => e } - def getType(): Option[Type] = { + def getType(): Type = { exp match { - case v: UIntValue => Option(UIntType(UnknownWidth)) - case v: SIntValue => Option(SIntType(UnknownWidth)) - case r: Ref => Option(r.tpe) - case s: Subfield => Option(s.tpe) - case i: Index => Option(i.tpe) - case p: DoPrimOp => Option(p.tpe) - case e: Exp => None + case v: UIntValue => UIntType(UnknownWidth) + case v: SIntValue => SIntType(UnknownWidth) + case r: Ref => r.tpe + case s: Subfield => s.tpe + case i: Index => i.tpe + case p: DoPrimOp => p.tpe } } } @@ -205,13 +207,13 @@ object Utils { // Using implicit types to allow overloading of function type to map, see StmtMagnet above def map[T](f: T => T)(implicit magnet: (T => T) => StmtMagnet): Stmt = magnet(f).map(stmt) - def getType(): Option[Type] = + def getType(): Type = stmt match { - case w: DefWire => Option(w.tpe) - case r: DefReg => Option(r.tpe) - case m: DefMemory => Option(m.tpe) - case p: DefPoison => Option(p.tpe) - case s: Stmt => None + case w: DefWire => w.tpe + case r: DefReg => r.tpe + case m: DefMemory => m.tpe + case p: DefPoison => p.tpe + case s: Stmt => UnknownType } } @@ -228,7 +230,7 @@ object Utils { implicit class FieldDirUtils(dir: FieldDir) { def serialize(implicit flags: FlagMap = FlagMap): String = { val s = dir match { - case Reverse => "flip " + case Reverse => "flip" case Default => "" } s + debug(dir) @@ -239,7 +241,7 @@ object Utils { def serialize(implicit flags: FlagMap = FlagMap): String = s"${field.dir.serialize} ${field.name} : ${field.tpe.serialize}" + debug(field) - def getType(): Option[Type] = Option(field.tpe) + def getType(): Type = field.tpe } implicit class TypeUtils(t: Type) { @@ -251,17 +253,18 @@ object Utils { case UnknownType => "?" case t: UIntType => s"UInt${t.width.serialize}" case t: SIntType => s"SInt${t.width.serialize}" - case t: BundleType => s"{ ${t.fields.map(_.serialize).mkString(commas)} }" + case t: BundleType => s"{${t.fields.map(_.serialize).mkString(commas)}}" case t: VectorType => s"${t.tpe.serialize}[${t.size}]" } - s + debug(t) + //s + debug(t) + s } // TODO how does this work? - def getType(): Option[Type] = + def getType(): Type = t match { - case v: VectorType => Option(v.tpe) - case tpe: Type => None + case v: VectorType => v.tpe + case tpe: Type => UnknownType } def wipeWidth(): Type = @@ -285,7 +288,7 @@ object Utils { implicit class PortUtils(p: Port) { def serialize(implicit flags: FlagMap = FlagMap): String = s"${p.dir.serialize} ${p.name} : ${p.tpe.serialize}" + debug(p) - def getType(): Option[Type] = Option(p.tpe) + def getType(): Type = p.tpe } implicit class ModuleUtils(m: Module) { -- cgit v1.2.3 From 7a7936c8fbddbffc1c4775fafeb5106ba1002dd4 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Oct 2015 13:50:36 -0700 Subject: Added infer-types pass, seems to work. Added infer-types error checking, modified Logger slightly, added Primops object for utility functions, minor changes in Utils --- src/main/scala/firrtl/Utils.scala | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/main/scala/firrtl/Utils.scala') diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index 0cf19f04..f024edc2 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -8,6 +8,7 @@ package firrtl import scala.collection.mutable.StringBuilder +import java.io.PrintWriter //import scala.reflect.runtime.universe._ object Utils { @@ -21,8 +22,7 @@ object Utils { var str = "" if (flags('types)) { val tpe = node.getType - //if( tpe != UnknownType ) str += s"@" - str += s"@" + if( tpe != UnknownType ) str += s"@" } str } @@ -46,8 +46,6 @@ object Utils { case p: Port => p.getType case _ => UnknownType } - - //def foreach } implicit class PrimOpUtils(op: PrimOp) { @@ -209,11 +207,11 @@ object Utils { def getType(): Type = stmt match { - case w: DefWire => w.tpe - case r: DefReg => r.tpe - case m: DefMemory => m.tpe - case p: DefPoison => p.tpe - case s: Stmt => UnknownType + case s: DefWire => s.tpe + case s: DefReg => s.tpe + case s: DefMemory => s.tpe + case s: DefPoison => s.tpe + case _ => UnknownType } } @@ -256,11 +254,9 @@ object Utils { case t: BundleType => s"{${t.fields.map(_.serialize).mkString(commas)}}" case t: VectorType => s"${t.tpe.serialize}[${t.size}]" } - //s + debug(t) - s + s + debug(t) } - // TODO how does this work? def getType(): Type = t match { case v: VectorType => v.tpe -- cgit v1.2.3 From 80c055ce93c9d5988c6158c4a91c01633f8ebf22 Mon Sep 17 00:00:00 2001 From: Jack Date: Thu, 15 Oct 2015 14:16:06 -0700 Subject: Reorganized Primops (renamed from PrimOps), added maps and functions to convert object <=> string, added eqv and neqv --- src/main/scala/firrtl/Utils.scala | 49 +++++---------------------------------- 1 file changed, 6 insertions(+), 43 deletions(-) (limited to 'src/main/scala/firrtl/Utils.scala') diff --git a/src/main/scala/firrtl/Utils.scala b/src/main/scala/firrtl/Utils.scala index f024edc2..4220e07f 100644 --- a/src/main/scala/firrtl/Utils.scala +++ b/src/main/scala/firrtl/Utils.scala @@ -9,6 +9,7 @@ package firrtl import scala.collection.mutable.StringBuilder import java.io.PrintWriter +import Primops._ //import scala.reflect.runtime.universe._ object Utils { @@ -48,46 +49,8 @@ object Utils { } } - implicit class PrimOpUtils(op: PrimOp) { - def serialize(implicit flags: FlagMap = FlagMap): String = { - op match { - case Add => "add" - case Sub => "sub" - case Addw => "addw" - case Subw => "subw" - case Mul => "mul" - case Div => "div" - case Mod => "mod" - case Quo => "quo" - case Rem => "rem" - case Lt => "lt" - case Leq => "leq" - case Gt => "gt" - case Geq => "geq" - case Eq => "eq" - case Neq => "neq" - case Mux => "mux" - case Pad => "pad" - case AsUInt => "asUInt" - case AsSInt => "asSInt" - case Shl => "shl" - case Shr => "shr" - case Dshl => "dshl" - case Dshr => "dshr" - case Cvt => "cvt" - case Neg => "neg" - case Not => "not" - case And => "and" - case Or => "or" - case Xor => "xor" - case Andr => "andr" - case Orr => "orr" - case Xorr => "xorr" - case Cat => "cat" - case Bit => "bit" - case Bits => "bits" - } - } + implicit class PrimopUtils(op: Primop) { + def serialize(implicit flags: FlagMap = FlagMap): String = op.getString } implicit class ExpUtils(exp: Exp) { @@ -98,7 +61,7 @@ object Utils { case r: Ref => r.name case s: Subfield => s"${s.exp.serialize}.${s.name}" case s: Index => s"${s.exp.serialize}[${s.value}]" - case p: DoPrimOp => + case p: DoPrimop => s"${p.op.serialize}(" + (p.args.map(_.serialize) ++ p.consts.map(_.toString)).mkString(", ") + ")" } ret + debug(exp) @@ -108,7 +71,7 @@ object Utils { exp match { case s: Subfield => Subfield(f(s.exp), s.name, s.tpe) case i: Index => Index(f(i.exp), i.value, i.tpe) - case p: DoPrimOp => DoPrimOp(p.op, p.args.map(f), p.consts, p.tpe) + case p: DoPrimop => DoPrimop(p.op, p.args.map(f), p.consts, p.tpe) case e: Exp => e } @@ -119,7 +82,7 @@ object Utils { case r: Ref => r.tpe case s: Subfield => s.tpe case i: Index => i.tpe - case p: DoPrimOp => p.tpe + case p: DoPrimop => p.tpe } } } -- cgit v1.2.3