Commit a8ffa3e5 authored by Kunshan Wang's avatar Kunshan Wang

Tested TextIRWriter

parent e2ff5a00
...@@ -3,7 +3,6 @@ package uvm.clientsupport.text ...@@ -3,7 +3,6 @@ package uvm.clientsupport.text
import scala.beans._ import scala.beans._
import java.util._ import java.util._
import DefaultTypes._ import DefaultTypes._
import uvm.ir.textinput.gen.UIRParser.TopLevelDefContext
/** /**
* This object contains common types and helper methods. * This object contains common types and helper methods.
...@@ -154,6 +153,11 @@ class ConstStruct() extends ConstDef { ...@@ -154,6 +153,11 @@ class ConstStruct() extends ConstDef {
@BeanProperty var fields: List[MuName] = makeList() @BeanProperty var fields: List[MuName] = makeList()
} }
/** A vector constant. */
class ConstVector() extends ConstDef {
@BeanProperty var elems: List[MuName] = makeList()
}
/** A NULL constant. */ /** A NULL constant. */
class ConstNull() extends ConstDef { class ConstNull() extends ConstDef {
} }
...@@ -379,9 +383,9 @@ trait FixedAlloc { ...@@ -379,9 +383,9 @@ trait FixedAlloc {
/** MixIn for hybrid allocation (NEWHYBRID and ALLOCAHYBRID) */ /** MixIn for hybrid allocation (NEWHYBRID and ALLOCAHYBRID) */
trait HybridAlloc { trait HybridAlloc {
/** The type to allocate. */ /** The type to allocate. */
@BeanProperty var allocTy: TypeHybrid = _ // T1 in spec @BeanProperty var allocTy: TypeMuName = _ // T1 in spec
/** The type of the length argument. Must be int. */ /** The type of the length argument. Must be int. */
@BeanProperty var lenTy: TypeInt = _ // T2 in spec @BeanProperty var lenTy: TypeMuName = _ // T2 in spec
/** The length. */ /** The length. */
@BeanProperty var length: VarMuName = _ @BeanProperty var length: VarMuName = _
} }
...@@ -507,20 +511,20 @@ class InstNewStack() extends Instruction with CallLike with HasExcClause ...@@ -507,20 +511,20 @@ class InstNewStack() extends Instruction with CallLike with HasExcClause
abstract class CurStackClause abstract class CurStackClause
/** RET_WITH */ /** RET_WITH */
case class RetWith( case class RetWith(
@BeanProperty var retTy: TypeMuName /* T1 */) extends CurStackClause @BeanProperty var retTy: TypeMuName /* T1 */ ) extends CurStackClause
/** KILL_OLD */ /** KILL_OLD */
case class KillOld() extends CurStackClause case class KillOld() extends CurStackClause
abstract class NewStackClause abstract class NewStackClause
/** PASS_VALUE */ /** PASS_VALUE */
case class PassValue( case class PassValue(
@BeanProperty var argTy: TypeMuName /* T2 */, @BeanProperty var argTy: TypeMuName /* T2 */ ,
@BeanProperty var arg: VarMuName) extends NewStackClause @BeanProperty var arg: VarMuName) extends NewStackClause
/** PASS_VOID */ /** PASS_VOID */
case class PassVoid() extends NewStackClause case class PassVoid() extends NewStackClause
/** THROW_EXC */ /** THROW_EXC */
case class ThrowExc( case class ThrowExc(
@BeanProperty var exc: VarMuName) extends NewStackClause @BeanProperty var exc: VarMuName) extends NewStackClause
/** SWAPSTACK */ /** SWAPSTACK */
class InstSwapStack() extends Instruction with HasExcClause with HasKeepAlives { class InstSwapStack() extends Instruction with HasExcClause with HasKeepAlives {
......
...@@ -5,7 +5,7 @@ import scala.collection.JavaConversions._ ...@@ -5,7 +5,7 @@ import scala.collection.JavaConversions._
object TextIRWriter { object TextIRWriter {
def bundleToText(bundle: Bundle): String = { def bundleToText(bundle: Bundle): String = {
val sb = new StringBuilder() val sb = new StringBuilder()
for (d <- bundle.typeDefs) sb ++= typeToText(d) ++= "\n" for (d <- bundle.typeDefs) sb ++= typeToText(d) ++= "\n"
for (d <- bundle.funcSigDefs) sb ++= funcSigToText(d) ++= "\n" for (d <- bundle.funcSigDefs) sb ++= funcSigToText(d) ++= "\n"
for (d <- bundle.constDefs) sb ++= constToText(d) ++= "\n" for (d <- bundle.constDefs) sb ++= constToText(d) ++= "\n"
...@@ -20,18 +20,13 @@ object TextIRWriter { ...@@ -20,18 +20,13 @@ object TextIRWriter {
def typeToText(typeDef: TypeDef): String = { def typeToText(typeDef: TypeDef): String = {
val name = typeDef.name val name = typeDef.name
val ctor = typeDef match { val ctor = typeDef match {
case t: TypeInt => "int<%d>".format(t.len) case t: TypeInt => "int<%d>".format(t.len)
case t: TypeFloat => "float" case t: TypeFloat => "float"
case t: TypeDouble => "double" case t: TypeDouble => "double"
case t: TypeRef => "ref<%s>".format(t.ty) case t: TypeRef => "ref<%s>".format(t.ty)
case t: TypeIRef => "iref<%s>".format(t.ty) case t: TypeIRef => "iref<%s>".format(t.ty)
case t: TypeWeakRef => "weakref<%s>".format(t.ty) case t: TypeWeakRef => "weakref<%s>".format(t.ty)
case t: TypeStruct => { case t: TypeStruct => "struct<%s>".format(t.fieldTy.mkString(" "))
val sb = new StringBuilder("struct<")
for (ty <- t.fieldTy) sb ++= " " ++= ty
sb ++= " >"
sb.toString
}
case t: TypeArray => "array<%s %d>".format(t.elemTy, t.len) case t: TypeArray => "array<%s %d>".format(t.elemTy, t.len)
case t: TypeHybrid => "hybrid<%s %s>".format(t.fixedTy, t.varTy) case t: TypeHybrid => "hybrid<%s %s>".format(t.fixedTy, t.varTy)
case t: TypeVoid => "void" case t: TypeVoid => "void"
...@@ -47,27 +42,19 @@ object TextIRWriter { ...@@ -47,27 +42,19 @@ object TextIRWriter {
} }
def funcSigToText(funcSigDef: FuncSigDef): String = { def funcSigToText(funcSigDef: FuncSigDef): String = {
val paramTys = { val paramTys = funcSigDef.paramTy.mkString(" ")
val sb = new StringBuilder(" ") ".funcsig %s = %s (%s)".format(funcSigDef.name, funcSigDef.retTy, paramTys)
for (ty <- funcSigDef.paramTy) sb ++= ty ++= " "
sb.toString
}
".funcsig %s = %s (%s)".format(funcSigDef.name, funcSigDef.retTy, funcSigDef.paramTy)
} }
def constToText(constDef: ConstDef): String = { def constToText(constDef: ConstDef): String = {
val name = constDef.name val name = constDef.name
val ty = constDef.ty val ty = constDef.ty
val ctor: String = constDef match { val ctor: String = constDef match {
case c: ConstInt => c.num.toString case c: ConstInt => c.num.toString
case c: ConstFloat => "bitsf(0x%x)".format(java.lang.Float.floatToRawIntBits(c.num)) case c: ConstFloat => "bitsf(0x%x)".format(java.lang.Float.floatToRawIntBits(c.num))
case c: ConstDouble => "bitsd(0x%x)".format(java.lang.Double.doubleToRawLongBits(c.num)) case c: ConstDouble => "bitsd(0x%x)".format(java.lang.Double.doubleToRawLongBits(c.num))
case c: ConstStruct => { case c: ConstStruct => "{%s}".format(c.fields.mkString(" "))
val sb = new StringBuilder("{ ") case c: ConstVector => "VEC{%s}".format(c.elems.mkString(" "))
for (f <- c.fields) sb ++= f ++= " "
sb ++= "}"
sb.toString
}
case c: ConstNull => "NULL" case c: ConstNull => "NULL"
case c: ConstPointer => c.addr.toString case c: ConstPointer => c.addr.toString
} }
...@@ -109,8 +96,8 @@ object TextIRWriter { ...@@ -109,8 +96,8 @@ object TextIRWriter {
case i: InstBinOp => "%s <%s> %s %s %s".format(i.op, i.opndTy, i.op1, i.op2, maybeExcClause(i)) case i: InstBinOp => "%s <%s> %s %s %s".format(i.op, i.opndTy, i.op1, i.op2, maybeExcClause(i))
case i: InstCmp => "%s <%s> %s %s".format(i.op, i.opndTy, i.op1, i.op2) case i: InstCmp => "%s <%s> %s %s".format(i.op, i.opndTy, i.op1, i.op2)
case i: InstConv => "%s <%s %s> %s".format(i.op, i.fromTy, i.toTy, i.opnd) case i: InstConv => "%s <%s %s> %s".format(i.op, i.fromTy, i.toTy, i.opnd)
case i: InstSelect => "SELECT <%s %s> %s %s".format(i.condTy, i.opndTy, i.cond, i.ifTrue, i.ifFalse) case i: InstSelect => "SELECT <%s %s> %s %s %s".format(i.condTy, i.opndTy, i.cond, i.ifTrue, i.ifFalse)
case i: InstBranch => "BRAHCN %s".format(i.dest) case i: InstBranch => "BRANCH %s".format(i.dest)
case i: InstBranch2 => "BRANCH2 %s %s %s".format(i.cond, i.ifTrue, i.ifFalse) case i: InstBranch2 => "BRANCH2 %s %s %s".format(i.cond, i.ifTrue, i.ifFalse)
case i: InstSwitch => { case i: InstSwitch => {
val sHead = "SWITCH <%s> %s %s {\n".format(i.opndTy, i.opnd, i.defDest) val sHead = "SWITCH <%s> %s %s {\n".format(i.opndTy, i.opnd, i.defDest)
...@@ -143,13 +130,13 @@ object TextIRWriter { ...@@ -143,13 +130,13 @@ object TextIRWriter {
case i: InstThrow => "THROW %s".format(i.excVal) case i: InstThrow => "THROW %s".format(i.excVal)
case i: InstLandingPad => "LANDINGPAD" case i: InstLandingPad => "LANDINGPAD"
case i: InstExtractValue => "EXTRACTVALUE <%s %d> %s".format(i.strTy, i.index, i.opnd) case i: InstExtractValue => "EXTRACTVALUE <%s %d> %s".format(i.strTy, i.index, i.opnd)
case i: InstInsertValue => "INSERT <%s %d> %s %s".format(i.strTy, i.index, i.opnd, i.newVal) case i: InstInsertValue => "INSERTVALUE <%s %d> %s %s".format(i.strTy, i.index, i.opnd, i.newVal)
case i: InstExtractElement => "EXTRACTELEMENT <%s %s> %s %s".format(i.vecTy, i.indTy, i.opnd, i.index) case i: InstExtractElement => "EXTRACTELEMENT <%s %s> %s %s".format(i.vecTy, i.indTy, i.opnd, i.index)
case i: InstInsertElement => "INSERTELEMENT <%s %s> %s %s %s".format(i.vecTy, i.indTy, i.opnd, i.index, i.newVal) case i: InstInsertElement => "INSERTELEMENT <%s %s> %s %s %s".format(i.vecTy, i.indTy, i.opnd, i.index, i.newVal)
case i: InstShuffleVector => "SHUFFLEVECTOR <%s %s> %s %s %s".format(i.vecTy, i.maskTy, i.vec1, i.vec2, i.mask) case i: InstShuffleVector => "SHUFFLEVECTOR <%s %s> %s %s %s".format(i.vecTy, i.maskTy, i.vec1, i.vec2, i.mask)
case i: InstNew => "NEW <%s> %s".format(i.allocTy, maybeExcClause(i)) case i: InstNew => "NEW <%s> %s".format(i.allocTy, maybeExcClause(i))
case i: InstNewHybrid => "NEWHYBRID <%s %s> %s %s".format(i.allocTy, i.lenTy, i.length, maybeExcClause(i)) case i: InstNewHybrid => "NEWHYBRID <%s %s> %s %s".format(i.allocTy, i.lenTy, i.length, maybeExcClause(i))
case i: InstAlloca => "ALLOCA<%s> %s".format(i.allocTy, maybeExcClause(i)) case i: InstAlloca => "ALLOCA <%s> %s".format(i.allocTy, maybeExcClause(i))
case i: InstAllocaHybrid => "ALLOCAHYBRID <%s %s> %s %s".format(i.allocTy, i.lenTy, i.length, maybeExcClause(i)) case i: InstAllocaHybrid => "ALLOCAHYBRID <%s %s> %s %s".format(i.allocTy, i.lenTy, i.length, maybeExcClause(i))
case i: InstGetIRef => "GETIREF <%s> %s".format(i.referentTy, i.opnd) case i: InstGetIRef => "GETIREF <%s> %s".format(i.referentTy, i.opnd)
case i: InstGetFieldIRef => "GETFIELDIREF %s <%s %d> %s".format(maybePtr(i), i.referentTy, i.index, i.opnd) case i: InstGetFieldIRef => "GETFIELDIREF %s <%s %d> %s".format(maybePtr(i), i.referentTy, i.index, i.opnd)
...@@ -169,7 +156,7 @@ object TextIRWriter { ...@@ -169,7 +156,7 @@ object TextIRWriter {
case i: InstCCall => { case i: InstCCall => {
val argList = i.argList.mkString(" ") val argList = i.argList.mkString(" ")
val ka = maybeKeepAlives(i) val ka = maybeKeepAlives(i)
"CCALL %s <%s %s> %s %s %s".format(i.callConv, i.calleeTy, i.sig, i.callee, argList, ka) "CCALL %s <%s %s> %s (%s) %s".format(i.callConv, i.calleeTy, i.sig, i.callee, argList, ka)
} }
case i: InstNewStack => { case i: InstNewStack => {
val argList = i.argList.mkString(" ") val argList = i.argList.mkString(" ")
...@@ -178,11 +165,11 @@ object TextIRWriter { ...@@ -178,11 +165,11 @@ object TextIRWriter {
} }
case i: InstSwapStack => { case i: InstSwapStack => {
val curStackClause = i.curStackClause match { val curStackClause = i.curStackClause match {
case RetWith(t) => "RET_WITH(%s)".format(t) case RetWith(t) => "RET_WITH (%s)".format(t)
case KillOld() => "KILL_OLD" case KillOld() => "KILL_OLD"
} }
val newStackClause = i.newStackClause match { val newStackClause = i.newStackClause match {
case PassValue(t, v) => "PASS_VALUE(%s %s)".format(t, v) case PassValue(t, v) => "PASS_VALUE <%s> %s".format(t, v)
case PassVoid() => "PASS_VOID" case PassVoid() => "PASS_VOID"
case ThrowExc(e) => "THROW_EXC(%s)".format(e) case ThrowExc(e) => "THROW_EXC(%s)".format(e)
} }
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment