Commit 2376c1d9 authored by Kunshan Wang's avatar Kunshan Wang

More on client interface.

parent b4b9468d
......@@ -10,6 +10,20 @@ import uvm.ssavariables.AtomicRMWOptr._
case class Handle(ty: Type, vb: ValueBox)
abstract class TrapHandlerResult
case class TrapExit() extends TrapHandlerResult
case class TrapRebindPassValue(newStack: Handle, value: Handle) extends TrapHandlerResult
case class TrapRebindPassVoid(newStack: Handle) extends TrapHandlerResult
case class TrapRebindThrowExc(newStack: Handle, exc: Handle) extends TrapHandlerResult
trait TrapHandler {
def handleTrap(ca: ClientAgent, thread: Handle, stack: Handle, watchPointID: Int): TrapHandlerResult
}
trait UndefinedFunctionHandler {
def handleUndefinedFunction(functionID: Int): Unit
}
class ClientAgent(microVM: MicroVM) {
val handles = new HashSet[Handle]()
......@@ -221,7 +235,7 @@ class ClientAgent(microVM: MicroVM) {
val nb = BoxIRef(ob.objRef, ob.offset + TypeSizes.varPartOffsetOf(ht))
newHandle(nt, nb)
}
def load(ord: MemoryOrder, loc: Handle): Handle = {
throw new UvmRefImplException("Not Implemented")
}
......@@ -237,7 +251,7 @@ class ClientAgent(microVM: MicroVM) {
def atomicRMW(ord: MemoryOrder, op: AtomicRMWOptr, loc: Handle, opnd: Handle): Handle = {
throw new UvmRefImplException("Not Implemented")
}
def fence(ord: MemoryOrder): Unit = {
}
......@@ -248,4 +262,83 @@ class ClientAgent(microVM: MicroVM) {
def newThread(stack: Handle): Handle = {
throw new UvmRefImplException("Not Implemented")
}
def killStack(stack: Handle): Unit = {
throw new UvmRefImplException("Not Implemented")
}
def currentFuncVer(stack: Handle, frame: Int): Int = {
throw new UvmRefImplException("Not Implemented")
}
def currentInstruction(stack: Handle, frame: Int): Int = {
throw new UvmRefImplException("Not Implemented")
}
def dumpKeepalives(stack: Handle, frame: Int): Seq[Handle] = {
throw new UvmRefImplException("Not Implemented")
}
def popFrame(stack: Handle): Unit = {
throw new UvmRefImplException("Not Implemented")
}
def pushFrame = throw new UvmRefImplException("Not Implemented")
def tr64IsFp(handle: Handle): Boolean = {
OpHelper.tr64IsFp(handle.vb.asInstanceOf[BoxTagRef64].raw)
}
def tr64IsInt(handle: Handle): Boolean = {
OpHelper.tr64IsInt(handle.vb.asInstanceOf[BoxTagRef64].raw)
}
def tr64IsRef(handle: Handle): Boolean = {
OpHelper.tr64IsRef(handle.vb.asInstanceOf[BoxTagRef64].raw)
}
def tr64ToFp(handle: Handle): Handle = {
val raw = handle.vb.asInstanceOf[BoxTagRef64].raw
val box = new BoxDouble(OpHelper.tr64ToFp(raw))
newHandle(InternalTypes.DOUBLE, box)
}
def tr64ToInt(handle: Handle): Handle = {
val raw = handle.vb.asInstanceOf[BoxTagRef64].raw
val box = new BoxInt(OpHelper.tr64ToInt(raw))
newHandle(InternalTypes.I52, box)
}
def tr64ToRef(handle: Handle): Handle = {
val raw = handle.vb.asInstanceOf[BoxTagRef64].raw
val box = new BoxRef(OpHelper.tr64ToRef(raw))
newHandle(InternalTypes.REF_VOID, box)
}
def tr64ToTag(handle: Handle): Handle = {
val raw = handle.vb.asInstanceOf[BoxTagRef64].raw
val box = new BoxInt(OpHelper.tr64ToTag(raw))
newHandle(InternalTypes.I6, box)
}
def tr64FromFp(handle: Handle): Handle = {
val fp = handle.vb.asInstanceOf[BoxDouble].value
val box = new BoxTagRef64(OpHelper.fpToTr64(fp))
newHandle(InternalTypes.TAGREF64, box)
}
def tr64FromInt(handle: Handle): Handle = {
val i = handle.vb.asInstanceOf[BoxInt].value
val box = new BoxTagRef64(OpHelper.intToTr64(i.longValue))
newHandle(InternalTypes.TAGREF64, box)
}
def tr64FromRef(ref: Handle, tag: Handle): Handle = {
val refv = ref.vb.asInstanceOf[BoxRef].objRef
val tagv = tag.vb.asInstanceOf[BoxInt].value
val box = new BoxTagRef64(OpHelper.refToTr64(refv, tagv.longValue))
newHandle(InternalTypes.TAGREF64, box)
}
}
\ No newline at end of file
......@@ -4,26 +4,42 @@ import uvm.types._
import uvm.ir.textinput.IDFactory
import scala.collection.mutable.HashMap
import uvm.FuncSig
import uvm.IdentifiedSettable
object InternalIDFactory extends IDFactory(32768) // IDs from 32768-65535 are for implementation internal use.
object InternalTypes {
val VOID_TYPE = TypeVoid()
VOID_TYPE.id = InternalIDFactory.getID()
VOID_TYPE.name = Some("@uvm.internal.void_type")
private implicit class IdentifiedSettableAssignable[T <: IdentifiedSettable](i: T) {
def :=(name: String): T = {
i.id = InternalIDFactory.getID()
i.name = Some(name)
i
}
}
val BYTE_TYPE = TypeInt(8)
BYTE_TYPE.id = InternalIDFactory.getID()
BYTE_TYPE.name = Some("@uvm.internal.byte_type")
def internal(name: String) = "@uvm.internal.types." + name
val BYTE_ARRAY_TYPE = TypeHybrid(VOID_TYPE, BYTE_TYPE)
BYTE_ARRAY_TYPE.id = InternalIDFactory.getID()
BYTE_ARRAY_TYPE.name = Some("@uvm.internal.byte_array_type")
val VOID = TypeVoid() := internal("void")
val BYTE = TypeInt(8) := internal("byte")
val BYTE_ARRAY = TypeHybrid(VOID, BYTE) := internal("byte_array")
val DOUBLE = TypeDouble() := internal("double")
val I52 = TypeInt(52) := internal("i52")
val REF_VOID = TypeRef(VOID) := internal("ref_void")
val I6 = TypeInt(6) := internal("i6")
val TAGREF64 = TypeTagRef64() := internal("tagref64")
}
object InternalTypePool {
val irefPool = HashMap[Type, TypeIRef]()
def irefOf(t: Type): TypeIRef = irefPool.get(t).getOrElse(TypeIRef(t))
val funcPool = HashMap[FuncSig, TypeFunc]()
def funcOf(s: FuncSig): TypeFunc = funcPool.get(s).getOrElse(TypeFunc(s))
class LazyPool[FromT, ToT](factory: FromT => ToT) {
val pool = HashMap[FromT, ToT]()
def apply(obj: FromT): ToT = pool.get(obj).getOrElse(factory(obj))
}
object LazyPool {
def apply[FromT, ToT](factory: FromT => ToT): LazyPool[FromT, ToT] = new LazyPool[FromT, ToT](factory)
}
val irefOf = LazyPool(TypeIRef)
val funcOf = LazyPool(TypeFunc)
}
\ No newline at end of file
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