Commit 86fe9958 authored by Kunshan Wang's avatar Kunshan Wang

Trap handler and the TRAP instruction.

parent 3dd5c9cd
......@@ -22,7 +22,7 @@ class MicroVM(heapSize: Word = MicroVM.DEFAULT_HEAP_SIZE,
val constantPool = new ConstantPool(this)
val memoryManager = new MemoryManager(heapSize, globalSize, stackSize, this)
val threadStackManager = new ThreadStackManager(this)
//val trapManager = new TrapManager(this)
val trapManager = new TrapManager(this)
val clientAgents = new HashSet[ClientAgent]()
val irReader = new UIRTextReader(new IDFactory())
......
......@@ -247,11 +247,11 @@ class ClientAgent(microVM: MicroVM) {
val nb = uty match {
case TypeInt(l) =>
val bi: BigInt = l match {
case 8 => MemorySupport.loadByte(iRef)
case 8 => MemorySupport.loadByte(iRef)
case 16 => MemorySupport.loadShort(iRef)
case 32 => MemorySupport.loadInt(iRef)
case 64 => MemorySupport.loadLong(iRef)
case _ => throw new UnimplementedOprationException("Loading int of length %d is not supported".format(l))
case _ => throw new UnimplementedOprationException("Loading int of length %d is not supported".format(l))
}
BoxInt(OpHelper.unprepare(bi, l))
case _: TypeFloat =>
......@@ -310,11 +310,11 @@ class ClientAgent(microVM: MicroVM) {
case TypeInt(l) =>
val bi = nvb.asInstanceOf[BoxInt].value
l match {
case 8 => MemorySupport.storeByte(iRef, bi.byteValue)
case 8 => MemorySupport.storeByte(iRef, bi.byteValue)
case 16 => MemorySupport.storeShort(iRef, bi.shortValue)
case 32 => MemorySupport.storeInt(iRef, bi.intValue)
case 64 => MemorySupport.storeLong(iRef, bi.longValue)
case _ => throw new UnimplementedOprationException("Storing int of length %d is not supported".format(l))
case _ => throw new UnimplementedOprationException("Storing int of length %d is not supported".format(l))
}
BoxInt(OpHelper.unprepare(bi, l))
case _: TypeFloat =>
......@@ -483,7 +483,7 @@ class ClientAgent(microVM: MicroVM) {
def newStack(func: Handle, args: Seq[Handle]): Handle = {
val fv = func.vb.asInstanceOf[BoxFunc].func match {
case None => throw new UvmRuntimeException("Stack-bottom function must not be NULL")
case None => throw new UvmRuntimeException("Stack-bottom function must not be NULL")
case Some(v) => v
}
......@@ -576,4 +576,18 @@ class ClientAgent(microVM: MicroVM) {
newHandle(InternalTypes.TAGREF64, box)
}
// Internal methods for µVM
def putThread(thr: Option[InterpreterThread]): Handle = {
val t = InternalTypes.THREAD
val box = BoxThread(thr)
newHandle(t, box)
}
def putStack(sta: Option[InterpreterStack]): Handle = {
val t = InternalTypes.STACK
val box = BoxStack(sta)
newHandle(t, box)
}
}
\ No newline at end of file
......@@ -71,7 +71,7 @@ object TypeInferer {
case i: InstSelect => i.opndTy
case i: InstBranch => VOID
case i: InstBranch2 => VOID
case i: InstSelect => i.opndTy
case i: InstSwitch => VOID
case i: InstPhi => i.opndTy
case i: InstCall => i.sig.retTy
case i: InstTailCall => VOID
......
package uvm.refimpl.itpr
import uvm.refimpl._
class TrapManager(microVM: MicroVM) {
var trapHandler: TrapHandler = DefaultTrapHandler
var undefinedFunctionHandler: UndefinedFunctionHandler = DefaultUndefinedFunctionHandler
object DefaultTrapHandler extends TrapHandler {
def handleTrap(ca: ClientAgent, thread: Handle, stack: Handle, watchPointID: Int): TrapHandlerResult = {
val thr = thread.vb.asInstanceOf[BoxThread].thread.get
val thrID = thr.id
val funcVerID = ca.currentFuncVer(stack, 0)
val funcVer = microVM.globalBundle.funcVerNs(funcVerID)
val instID = ca.currentInstruction(stack, 0)
val inst = microVM.globalBundle.varNs(instID)
throw new UvmRuntimeException("Unhandled trap. Thread %d, funcver %s, trap inst %s, watch point ID %d".format(
thr.id, funcVer.repr, inst.repr, watchPointID))
}
}
object DefaultUndefinedFunctionHandler extends UndefinedFunctionHandler {
def handleUndefinedFunction(functionID: Int): Unit = {
val func = microVM.globalBundle.funcNs(functionID)
throw new UvmRuntimeException("Unhandled undefined function. Function %s.".format(func.repr))
}
}
}
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