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())
......
......@@ -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