From 1d8bf3c1b15b4075fa570b3c8e6715fa7a410c70 Mon Sep 17 00:00:00 2001 From: Kunshan Wang Date: Mon, 21 Sep 2015 23:53:54 +1000 Subject: [PATCH] Cookie. --- .../uvm/refimpl/itpr/InterpreterThread.scala | 17 +++++++++++++- src/main/scala/uvm/refimpl/itpr/stacks.scala | 23 ++++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/main/scala/uvm/refimpl/itpr/InterpreterThread.scala b/src/main/scala/uvm/refimpl/itpr/InterpreterThread.scala index 729af1a..dc980c0 100644 --- a/src/main/scala/uvm/refimpl/itpr/InterpreterThread.scala +++ b/src/main/scala/uvm/refimpl/itpr/InterpreterThread.scala @@ -1127,6 +1127,21 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator continueNormally() } + + case "@uvm.native.expose" => { + ??? + } + + case "@uvm.native.unexpose" => { + ??? + } + + case "@uvm.native.get_cookie" => { + val cookie = topMu.cookie + boxOf(i).asInstanceOf[BoxInt].value = OpHelper.trunc(cookie, 64) + continueNormally() + } + // Insert more CommInsts here. case ciName => { @@ -1280,7 +1295,7 @@ class InterpreterThread(val id: Int, initialStack: InterpreterStack, val mutator val funcVer = getFuncDefOrTriggerCallback(func) curInstHalfExecuted = true - curStack.pushMuFrame(funcVer, args) + curStack.pushMuFrameForCallBack(funcVer, cookie, args) } case NativeCallResult.Return() => { continueNormally() diff --git a/src/main/scala/uvm/refimpl/itpr/stacks.scala b/src/main/scala/uvm/refimpl/itpr/stacks.scala index b3c1883..b5f4c6f 100644 --- a/src/main/scala/uvm/refimpl/itpr/stacks.scala +++ b/src/main/scala/uvm/refimpl/itpr/stacks.scala @@ -28,7 +28,7 @@ class InterpreterStack(val id: Int, val stackMemory: StackMemory, stackBottomFun def state = _state private def state_=(s: StackState) = _state = s - private var _top: InterpreterFrame = InterpreterFrame.forMuFunc(stackBottomFunc, args, None) + private var _top: InterpreterFrame = InterpreterFrame.forMuFunc(stackBottomFunc, 0L, args, None) def top = _top private def top_=(f: InterpreterFrame) = _top = f @@ -54,13 +54,19 @@ class InterpreterStack(val id: Int, val stackMemory: StackMemory, stackBottomFun def muFrames: Iterator[MuFrame] = frames.filter(_.isInstanceOf[MuFrame]).map(_.asInstanceOf[MuFrame]) def pushMuFrame(funcVer: FuncVer, args: Seq[ValueBox]): Unit = { - val newFrame = InterpreterFrame.forMuFunc(funcVer, args, Some(top)) + val newFrame = InterpreterFrame.forMuFunc(funcVer, 0L, args, Some(top)) + top = newFrame + top.savedStackPointer = stackMemory.top + } + + def pushMuFrameForCallBack(funcVer: FuncVer, cookie: Long, args: Seq[ValueBox]): Unit = { + val newFrame = InterpreterFrame.forMuFunc(funcVer, cookie, args, Some(top)) top = newFrame top.savedStackPointer = stackMemory.top } def replaceTopMuFrame(funcVer: FuncVer, args: Seq[ValueBox]): Unit = { - val newFrame = InterpreterFrame.forMuFunc(funcVer, args, top.prev) + val newFrame = InterpreterFrame.forMuFunc(funcVer, 0L, args, top.prev) stackMemory.rewind(top.savedStackPointer) top = newFrame top.savedStackPointer = stackMemory.top @@ -137,8 +143,8 @@ abstract class InterpreterFrame(val prev: Option[InterpreterFrame]) { } object InterpreterFrame { - def forMuFunc(funcVer: FuncVer, args: Seq[ValueBox], prev: Option[InterpreterFrame]): MuFrame = { - val frm = new MuFrame(funcVer, prev) // Bottom frame + def forMuFunc(funcVer: FuncVer, cookie: Long, args: Seq[ValueBox], prev: Option[InterpreterFrame]): MuFrame = { + val frm = new MuFrame(funcVer, cookie, prev) // Bottom frame for ((p, a) <- (funcVer.params zip args)) { frm.boxes(p).copyFrom(a) @@ -153,7 +159,12 @@ object InterpreterFrame { } } -class MuFrame(val funcVer: FuncVer, prev: Option[InterpreterFrame]) extends InterpreterFrame(prev) { +/** + * A Mu frame + * + * @param cookie: The cookie in the native interface. When called by another Mu function, cookie can be any value. + */ +class MuFrame(val funcVer: FuncVer, val cookie: Long, prev: Option[InterpreterFrame]) extends InterpreterFrame(prev) { val boxes = new HashMap[LocalVariable, ValueBox]() /** Edge-assigned instructions take values determined at look backedges */ -- 2.26.2