WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

types.scala 1.95 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
package uvm.types

import uvm._

abstract class Type extends IdentifiedSettable {
  override final def toString: String = Type.prettyPrint(this)
}

case class TypeInt(var length: Int) extends Type
case class TypeFloat() extends Type
case class TypeDouble() extends Type
case class TypeRef(var ty: Type) extends Type
case class TypeIRef(var ty: Type) extends Type
case class TypeWeakRef(var ty: Type) extends Type
case class TypeStruct(var fieldTy: Seq[Type]) extends Type
case class TypeArray(var elemTy: Type, var len: Long) extends Type
case class TypeHybrid(var fixedPart: Type, var varPart: Type) extends Type
case class TypeVoid extends Type
case class TypeFunc(var sig: FuncSig) extends Type
case class TypeThread() extends Type
case class TypeStack() extends Type
case class TypeTagRef64 extends Type

object Type {
  def prettyPrint(ty: Type): String = ty match {
    case TypeInt(length) => "int<%d>".format(length)
    case TypeFloat() => "float"
    case TypeDouble() => "double"
    case TypeRef(ty) => "ref<%s>".format(ty.repr)
    case TypeIRef(ty) => "iref<%s>".format(ty.repr)
    case TypeWeakRef(ty) => "weakref<%s>".format(ty.repr)
    case TypeStruct(fieldTy) => "struct<%s>".format(fieldTy.map(_.repr).mkString(" "))
    case TypeArray(elemTy, len) => "array<%s %d>".format(elemTy.repr, len)
    case TypeHybrid(fixedPart, varPart) => "hybrid<%s %s>".format(fixedPart.repr, varPart.repr)
    case TypeVoid() => "void"
    case TypeFunc(sig) => "func<%s>".format(FuncSig.prettyPrint(sig))
    case TypeThread() => "thread"
    case TypeStack() => "stack"
    case TypeTagRef64() => "tagref64"
    case _ => "unknown type " + ty.getClass.getName
  }
}

object CommonTypes {
  val I1 = TypeInt(1)
  val I8 = TypeInt(8)
  val I16 = TypeInt(16)
  val I32 = TypeInt(32)
  val I64 = TypeInt(64)
  val IWORD = TypeInt(64)
  val FLOAT = TypeFloat()
  val DOUBLE = TypeDouble()
  val VOID = TypeVoid()
  val REFVOID = TypeRef(VOID)
  val THREAD = TypeThread()
  val STACK = TypeStack()
}