Commit 0bb90c20 authored by Kunshan Wang's avatar Kunshan Wang

Refactor and compile again.

TODO: Implement the new IR builder.
parent 083afc1a
......@@ -61,7 +61,7 @@ typeConstructor
| 'threadref' # TypeThreadRef
| 'stackref' # TypeStackRef
| 'framecursorref' # TypeFrameCursorRef
| 'irnoderef' # TypeIRNodeRef
| 'irbuilderref' # TypeIRBuilderRef
;
funcSigConstructor
......
......@@ -202,7 +202,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
case t: TypeThreadRefContext => TypeThreadRef()
case t: TypeStackRefContext => TypeStackRef()
case t: TypeFrameCursorRefContext => TypeFrameCursorRef()
case t: TypeIRNodeRefContext => TypeIRNodeRef()
case t: TypeIRBuilderRefContext => TypeIRBuilderRef()
}
return ty
}
......
package uvm.refimpl
import java.io.OutputStreamWriter
import java.io.Writer
import scala.collection.mutable.HashSet
......@@ -10,18 +9,17 @@ import uvm._
import uvm.ir.irbuilder.IRBuilder
import uvm.ir.textinput.UIRTextReader
import uvm.ir.textoutput.BundleSerializer
import uvm.ir.textoutput.DebugBundleSerializer
import uvm.refimpl.bootimg.BootImageBuilder
import uvm.refimpl.bootimg.BootImageLoader
import uvm.refimpl.hail.HailScriptLoader
import uvm.refimpl.itpr._
import uvm.refimpl.mem._
import uvm.refimpl.mem.TypeSizes.Word
import uvm.refimpl.nat.NativeCallHelper
import uvm.refimpl.nat.NativeLibraryHolder
import uvm.staticanalysis.StaticAnalyzer
import uvm.utils.IDFactory
import uvm.utils.WithUtils.tryWithResource
import uvm.ir.textoutput.DebugBundleSerializer
object MicroVM {
val DEFAULT_SOS_SIZE: Word = 2L * 1024L * 1024L; // 2MiB
......@@ -60,8 +58,7 @@ class MicroVM(val vmConf: VMConf) {
val contexts = new HashSet[MuCtx]()
val idFactory = IDFactory.newClientIDFactory()
val irBuilder = new IRBuilder(globalBundle, idFactory)
val irNodeRegistry = new SequentialObjectKeeper[IRNode]()
val irBuilderRegistry = new SequentialObjectKeeper[IRBuilder]()
val irReader = new UIRTextReader(idFactory, recordSourceInfo = vmConf.sourceInfo)
val hailScriptLoader = new HailScriptLoader(recordSourceInfo = vmConf.sourceInfo)
val staticAnalyzer = new StaticAnalyzer()
......
......@@ -32,7 +32,7 @@ object MuCtx {
* operations on the Mu VM.
*/
class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
implicit protected val microVM: MicroVM, memorySupport: MemorySupport)
implicit protected val microVM: MicroVM, memorySupport: MemorySupport)
extends ObjectPinner with AutoCloseable {
import MuCtx._
......@@ -54,7 +54,7 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
mutator.close()
microVM.contexts.remove(this)
}
/** Synonym of closeContext, for AutoCloseable. */
override def close(): Unit = closeContext()
......@@ -192,10 +192,7 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
def refEq(lhs: MuGenRefValue, rhs: MuGenRefValue): Boolean = (lhs, rhs) match {
case (l: MuRefValue, r: MuRefValue) => l.vb.objRef == r.vb.objRef
case (l: MuIRefValue, r: MuIRefValue) => l.vb.oo == r.vb.oo
case (l: MuFuncRefValue, r: MuFuncRefValue) => l.vb.func == r.vb.func
case (l: MuThreadRefValue, r: MuThreadRefValue) => l.vb.thread == r.vb.thread
case (l: MuStackRefValue, r: MuStackRefValue) => l.vb.stack == r.vb.stack
case (l: MuFCRefValue, r: MuFCRefValue) => l.vb.cursor == r.vb.cursor
case (l: MuOpaqueRefValue[_], r: MuOpaqueRefValue[_]) => l.vb.obj == r.vb.obj
case (l, r) => {
throw new IllegalArgumentException("Bad types for refEq: %s and %s".format(
l.showTy, r.showTy))
......@@ -275,7 +272,11 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
val nh = (opnd, nt) match {
case (MuRefValue(ty, vb), ty2 @ TypeRef(_)) => MuRefValue(ty2, vb)
case (MuIRefValue(ty, vb), ty2 @ TypeIRef(_)) => MuIRefValue(ty2, vb)
case (MuFuncRefValue(ty, vb), ty2 @ TypeFuncRef(_)) => MuFuncRefValue(ty2, vb)
case (MuOpaqueRefValue(ty, vb), ty2 @ TypeFuncRef(_)) => {
require(ty.isInstanceOf[TypeFuncRef] && vb.isInstanceOf[BoxOpaque[_]],
"Attempt to cast %s to funcref. funcref value required".format(opnd.showTy))
MuFuncRefValue(ty2, vb.asInstanceOf[BoxFunc])
}
case _ => {
throw new IllegalArgumentException("Bad types for refcast: opnd:%s, newType:%s".format(
opnd.showTy, nt.repr))
......@@ -412,7 +413,7 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
/** Create a Mu stack with fa stack-bottom function */
def newStack(func: MuFuncRefValue): MuStackRefValue = {
val funcVal = func.vb.asInstanceOf[BoxFunc].func.getOrElse {
val funcVal = func.vb.obj.getOrElse {
throw new UvmRuntimeException("Stack-bottom function must not be NULL")
}
......@@ -423,13 +424,13 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
}
private def getStackNotNull(stack: MuStackRefValue): InterpreterStack = {
stack.vb.stack.getOrElse {
stack.vb.obj.getOrElse {
throw new UvmRuntimeException("Stack argument cannot be a NULL stackref value.")
}
}
private def getThreadNotNull(thread: MuThreadRefValue): InterpreterThread = {
thread.vb.thread.getOrElse {
thread.vb.obj.getOrElse {
throw new UvmRuntimeException("Thread argument cannot be a NULL threadref value.")
}
}
......@@ -474,7 +475,7 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
}
private def getCursorNotNull(cursor: MuFCRefValue): FrameCursor = {
cursor.vb.cursor.getOrElse {
cursor.vb.obj.getOrElse {
throw new UvmRuntimeException("Frame cursor argument cannot be a NULL framecursorref value.")
}
}
......@@ -573,7 +574,7 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
def pushFrame(stack: MuStackRefValue, func: MuFuncRefValue): Unit = {
val st = getStackNotNull(stack)
val funcVal = func.vb.asInstanceOf[BoxFunc].func.getOrElse {
val funcVal = func.vb.obj.getOrElse {
throw new UvmRuntimeException("Stack-bottom function must not be NULL")
}
......@@ -682,7 +683,7 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
def expose(func: MuFuncRefValue, callConv: Flag, cookie: MuIntValue): MuUFPValue = {
val TypeFuncRef(sig) = func.ty
val f = func.vb.func.getOrElse {
val f = func.vb.obj.getOrElse {
throw new UvmRuntimeException("Attempt to expose NULL Mu function")
}
......@@ -696,7 +697,7 @@ class MuCtx(val ctxID: MuInternalID, _mutator: Mutator)(
val a = addr.vb.addr
microVM.nativeCallHelper.unexposeFunc(a)
}
def newIRBuilder(): IRBuilder = {
new IRBuilder(microVM.globalBundle, microVM.idFactory)
}
......
......@@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
import uvm._
import uvm.ir.irbuilder.IRBuilder
import uvm.ir.textoutput.BundleSerializer
import uvm.ir.textoutput.EntityUtils
import uvm.refimpl._
......@@ -240,7 +241,7 @@ class BootImageWriter(tcb: TransitiveClosureBuilder, outputFile: String)(implici
def visitStackRefField(objRef: Word, iRef: Word, toStack: Option[InterpreterStack]): Unit = {}
def visitThreadRefField(objRef: Word, iRef: Word, toThread: Option[InterpreterThread]): Unit = {}
def visitFCRefField(objRef: Word, iRef: Word, toFCRef: Option[FrameCursor]): Unit = {}
def visitIRNodeRefField(objRef: Word, iRef: Word, toIRNode: Option[IRNode]): Unit = {}
def visitIRBuilderRefField(objRef: Word, iRef: Word, toIRNode: Option[IRBuilder]): Unit = {}
})
}
}
......
......@@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
import uvm._
import uvm.ir.irbuilder.IRBuilder
import uvm.refimpl._
import uvm.refimpl.itpr._
import uvm.refimpl.mem.HeaderUtils
......@@ -15,9 +16,9 @@ import uvm.refimpl.mem.Space
import uvm.refimpl.mem.TypeSizes
import uvm.refimpl.mem.TypeSizes.Word
import uvm.refimpl.mem.scanning.MemoryDataScanner
import uvm.refimpl.mem.scanning.MemoryFieldHandler
import uvm.ssavariables._
import uvm.types._
import uvm.refimpl.mem.scanning.MemoryFieldHandler
object TransitiveClosure {
def apply[T](initialElems: T*) = new TransitiveClosure(initialElems)
......@@ -356,8 +357,8 @@ class TransitiveClosureBuilder(initialSet: Seq[TopLevel])(implicit microVM: Micr
toThread.foreach(o => throw noReach("thread", objRef, iRef, o))
override def visitFCRefField(objRef: Word, iRef: Word, toFCRef: Option[FrameCursor]): Unit =
toFCRef.foreach(o => throw noReach("frame cursor", objRef, iRef, o))
override def visitIRNodeRefField(objRef: Word, iRef: Word, toIRNode: Option[IRNode]): Unit =
toIRNode.foreach(o => throw noReach("IR node", objRef, iRef, o))
override def visitIRBuilderRefField(objRef: Word, iRef: Word, toIRNode: Option[IRBuilder]): Unit =
toIRNode.foreach(o => throw noReach("IR builder", objRef, iRef, o))
private def noReach(kind: String, objRef: Word, iRef: Word, obj: AnyRef) =
new BootImageBuilderException(
......
......@@ -10,22 +10,20 @@ import uvm.ssavariables.MemoryOrder._
import uvm.types._
object MuValue {
import ValueBox._
def apply(ty: Type, vb: ValueBox): MuValue = (ty, vb) match {
case (t: TypeInt, v: BoxInt) => MuIntValue(t, v)
case (t: TypeFloat, v: BoxFloat) => MuFloatValue(t, v)
case (t: TypeDouble, v: BoxDouble) => MuDoubleValue(t, v)
case (t: TypeRef, v: BoxRef) => MuRefValue(t, v)
case (t: TypeIRef, v: BoxIRef) => MuIRefValue(t, v)
case (t: TypeStruct, v: BoxSeq) => MuStructValue(t, v)
case (t: TypeArray, v: BoxSeq) => MuArrayValue(t, v)
case (t: TypeVector, v: BoxSeq) => MuVectorValue(t, v)
case (t: TypeFuncRef, v: BoxFunc) => MuFuncRefValue(t, v)
case (t: TypeThreadRef, v: BoxThread) => MuThreadRefValue(t, v)
case (t: TypeStackRef, v: BoxStack) => MuStackRefValue(t, v)
case (t: TypeTagRef64, v: BoxTagRef64) => MuTagRef64Value(t, v)
case (t: TypeUPtr, v: BoxPointer) => MuUPtrValue(t, v)
case (t: TypeUFuncPtr, v: BoxPointer) => MuUFPValue(t, v)
case (t: TypeFrameCursorRef, v: BoxFrameCursor) => MuFCRefValue(t, v)
case (t: TypeInt, v: BoxInt) => MuIntValue(t, v)
case (t: TypeFloat, v: BoxFloat) => MuFloatValue(t, v)
case (t: TypeDouble, v: BoxDouble) => MuDoubleValue(t, v)
case (t: TypeRef, v: BoxRef) => MuRefValue(t, v)
case (t: TypeIRef, v: BoxIRef) => MuIRefValue(t, v)
case (t: TypeStruct, v: BoxSeq) => MuStructValue(t, v)
case (t: TypeArray, v: BoxSeq) => MuArrayValue(t, v)
case (t: TypeVector, v: BoxSeq) => MuVectorValue(t, v)
case (t: TypeTagRef64, v: BoxTagRef64) => MuTagRef64Value(t, v)
case (t: TypeUPtr, v: BoxPointer) => MuUPtrValue(t, v)
case (t: TypeUFuncPtr, v: BoxPointer) => MuUFPValue(t, v)
case (t: AbstractOpaqueRefType, v: BoxOpaque[_]) => MuOpaqueRefValue(t, v) // type ignored
case (t, v) => {
throw new IllegalArgumentException("Improper type-box pair: %s,%s".format(t.toString, vb.getClass.getSimpleName))
}
......@@ -53,30 +51,27 @@ abstract class MuGenRefValue extends MuValue {
def isNull: Boolean
}
abstract class MuSpecialEntityRefValue[+T] extends MuGenRefValue {
def vb: ObjectBox[_]
def isNull: Boolean = vb.obj.isEmpty
}
case class MuIntValue(ty: TypeInt, vb: BoxInt) extends MuValue
case class MuFloatValue(ty: TypeFloat, vb: BoxFloat) extends MuValue
case class MuDoubleValue(ty: TypeDouble, vb: BoxDouble) extends MuValue
case class MuUPtrValue(ty: TypeUPtr, vb: BoxPointer) extends MuValue
case class MuUFPValue(ty: TypeUFuncPtr, vb: BoxPointer) extends MuValue
case class MuStructValue(ty: TypeStruct, vb: BoxSeq) extends MuValue
case class MuArrayValue(ty: TypeArray, vb: BoxSeq) extends MuSeqValue
case class MuVectorValue(ty: TypeVector, vb: BoxSeq) extends MuSeqValue
case class MuRefValue(ty: TypeRef, vb: BoxRef) extends MuGenRefValue {
override def isNull: Boolean = vb.objRef == 0L
}
case class MuIRefValue(ty: TypeIRef, vb: BoxIRef) extends MuGenRefValue {
override def isNull: Boolean = vb.objRef + vb.offset == 0L
}
case class MuStructValue(ty: TypeStruct, vb: BoxSeq) extends MuValue
case class MuArrayValue(ty: TypeArray, vb: BoxSeq) extends MuSeqValue
case class MuVectorValue(ty: TypeVector, vb: BoxSeq) extends MuSeqValue
case class MuFuncRefValue(ty: TypeFuncRef, vb: BoxFunc) extends MuSpecialEntityRefValue[Function]
case class MuThreadRefValue(ty: TypeThreadRef, vb: BoxThread) extends MuSpecialEntityRefValue[InterpreterThread]
case class MuStackRefValue(ty: TypeStackRef, vb: BoxStack) extends MuSpecialEntityRefValue[InterpreterStack]
case class MuTagRef64Value(ty: TypeTagRef64, vb: BoxTagRef64) extends MuValue
case class MuUPtrValue(ty: TypeUPtr, vb: BoxPointer) extends MuValue
case class MuUFPValue(ty: TypeUFuncPtr, vb: BoxPointer) extends MuValue
case class MuFCRefValue(ty: TypeFrameCursorRef, vb: BoxFrameCursor) extends MuSpecialEntityRefValue[FrameCursor]
case class MuOpaqueRefValue[T](ty: AbstractOpaqueRefType, vb: BoxOpaque[T]) extends MuGenRefValue {
def isNull: Boolean = vb.obj.isEmpty
}
abstract class TrapHandlerResult
object TrapHandlerResult {
......
......@@ -44,14 +44,6 @@ trait IRBuilderCommInstExecutor extends InterpreterActions with ObjectPinner {
implicit protected def mutator: Mutator
implicit protected def memorySupport: MemorySupport
protected def irBuilder = microVM.irBuilder
protected def loadIRNodeArray[T <: IRNode](ir: (Word, Word), sz: Word): IndexedSeq[T] = {
val (obj,off) = ir
val loc = obj + off
MemoryOperations.loadIRNodeArray(loc, sz).asInstanceOf[IndexedSeq[T]]
}
protected def loadInt64Array(ir: (Word, Word), sz: Word): IndexedSeq[Long] = {
val (obj,off) = ir
val loc = obj + off
......
......@@ -2,20 +2,20 @@ package uvm.refimpl.itpr
import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
import uvm._
import uvm.comminsts._
import uvm.ir.irbuilder.IRBuilder
import uvm.refimpl._
import uvm.refimpl.{ HowToResume => ClientHowToResume }
import uvm.refimpl.mem._
import uvm.refimpl.mem.TypeSizes.Word
import uvm.ssavariables._
import uvm.types._
import uvm.refimpl.nat.NativeCallResult
import uvm.refimpl.itpr.BoxIRBuilder
import uvm.ir.irbuilder.IRBuilder
import uvm.refimpl.itpr.BoxIRBuilder
object InterpreterThread {
val logger = Logger(LoggerFactory.getLogger(getClass.getName))
......@@ -38,7 +38,6 @@ object HowToResume {
*/
class InterpreterThread(val id: MuInternalID, initialStack: InterpreterStack, initialThreadLocal: Long, htr: HowToResume, val mutator: Mutator)(
implicit protected val microVM: MicroVM) extends InstructionExecutor with HasID {
import InterpreterThread._
// Injectable resources (used by memory access instructions)
implicit protected val memorySupport = microVM.memoryManager.memorySupport
......@@ -423,7 +422,7 @@ trait InterpreterActions extends InterpreterThreadState {
isRunning = false
}
case TrapHandlerResult.Rebind(newStack, htr) => {
val ns = newStack.vb.stack.getOrElse {
val ns = newStack.vb.obj.getOrElse {
throw new UvmNullGenRefException(curCtx + "Attempt to rebind to NULL stack when returning from trap.")
}
......@@ -519,7 +518,7 @@ object MagicalBox {
def asIRef: (Word, Word) = box.asInstanceOf[BoxIRef].oo
def asIRefLoc: Word = box.asInstanceOf[BoxIRef].addr
def asTR64Raw: Long = box.asInstanceOf[BoxTagRef64].raw
def asFunc: Option[Function] = box.asInstanceOf[BoxFunc].func
def asFunc: Option[Function] = box.asInstanceOf[BoxFunc].obj
def asThread: Option[InterpreterThread] = box.asInstanceOf[BoxThread].obj
def asStack: Option[InterpreterStack] = box.asInstanceOf[BoxStack].obj
def asFrameCursor: Option[FrameCursor] = box.asInstanceOf[BoxFrameCursor].obj
......
......@@ -17,8 +17,8 @@ class TrapManager(implicit microVM: MicroVM) {
object DefaultTrapHandler extends TrapHandler {
def handleTrap(ctx: MuCtx, thread: MuThreadRefValue, stack: MuStackRefValue, watchPointID: MuID): TrapHandlerResult = {
val thrID = thread.vb.asInstanceOf[BoxThread].thread.get.id
val staID = stack.vb.asInstanceOf[BoxStack].stack.get.id
val thrID = thread.vb.obj.get.id
val staID = stack.vb.obj.get.id
val cursor = ctx.newCursor(stack)
val curFuncID = ctx.curFunc(cursor)
val curFuncVerID = ctx.curFuncVer(cursor)
......
......@@ -5,6 +5,7 @@ import uvm.types._
import uvm.refimpl._
import uvm.refimpl.mem.TypeSizes.Word
import uvm.ir.irbuilder.IRBuilder
import uvm.refimpl.mem.EntityAccessors.CanBeIntegerized
abstract class ValueBox {
def copyFrom(other: ValueBox): Unit
......@@ -16,13 +17,6 @@ abstract class HasObjRef extends ValueBox {
def setObjRef(newObjRef: Word): Unit
}
abstract class ObjectBox[T] extends ValueBox {
def obj: Option[T]
def obj_=(o: Option[T]): Unit
def copyFrom(other: ValueBox): Unit = { this.obj = other.asInstanceOf[ObjectBox[T]].obj }
}
case class BoxInt(var value: BigInt) extends ValueBox {
def copyFrom(other: ValueBox): Unit = { this.value = other.asInstanceOf[BoxInt].value }
}
......@@ -32,6 +26,12 @@ case class BoxFloat(var value: Float) extends ValueBox {
case class BoxDouble(var value: Double) extends ValueBox {
def copyFrom(other: ValueBox): Unit = { this.value = other.asInstanceOf[BoxDouble].value }
}
case class BoxPointer(var addr: Word) extends ValueBox {
def copyFrom(other: ValueBox): Unit = {
val that = other.asInstanceOf[BoxPointer]
this.addr = that.addr
}
}
case class BoxSeq(var values: Seq[ValueBox]) extends ValueBox {
def copyFrom(other: ValueBox): Unit = { for ((t, o) <- this.values.zip(other.asInstanceOf[BoxSeq].values)) t.copyFrom(o) }
}
......@@ -57,26 +57,6 @@ case class BoxIRef(var objRef: Word, var offset: Word) extends HasObjRef {
// Helper to get the address (objRef + offset). Useful when accessing the memory.
def addr: Word = objRef + offset
}
case class BoxFunc(var func: Option[Function]) extends ObjectBox[Function] {
def obj = func
def obj_=(other: Option[Function]): Unit = { func = other }
}
case class BoxThread(var thread: Option[InterpreterThread]) extends ObjectBox[InterpreterThread] {
def obj = thread
def obj_=(other: Option[InterpreterThread]): Unit = { thread = other }
}
case class BoxStack(var stack: Option[InterpreterStack]) extends ObjectBox[InterpreterStack] {
def obj = stack
def obj_=(other: Option[InterpreterStack]): Unit = { stack = other }
}
case class BoxFrameCursor(var cursor: Option[FrameCursor]) extends ObjectBox[FrameCursor] {
def obj = cursor
def obj_=(other: Option[FrameCursor]): Unit = { cursor = other }
}
case class BoxIRBuilder(var builder: Option[IRBuilder]) extends ObjectBox[IRBuilder] {
def obj = builder
def obj_=(other: Option[IRBuilder]): Unit = { builder = other }
}
case class BoxTagRef64(var raw: Long) extends HasObjRef {
def copyFrom(other: ValueBox): Unit = { this.raw = other.asInstanceOf[BoxTagRef64].raw }
def hasObjRef() = OpHelper.tr64IsRef(raw)
......@@ -86,13 +66,11 @@ case class BoxTagRef64(var raw: Long) extends HasObjRef {
raw = OpHelper.refToTr64(newObjRef, oldTag)
}
}
case class BoxPointer(var addr: Word) extends ValueBox {
def copyFrom(other: ValueBox): Unit = {
val that = other.asInstanceOf[BoxPointer]
this.addr = that.addr
}
case class BoxOpaque[T: CanBeIntegerized](var obj: Option[T]) extends ValueBox {
def copyFrom(other: ValueBox): Unit = { this.obj = other.asInstanceOf[BoxOpaque[T]].obj }
}
object ValueBox {
def makeBoxForType(ty: Type): ValueBox = ty match {
......@@ -110,11 +88,11 @@ object ValueBox {
case _: TypeIRef => BoxIRef(0L, 0L)
case _: TypeWeakRef => throw new UvmRefImplException("weakref cannot be an SSA variable type")
case _: TypeTagRef64 => BoxTagRef64(0L)
case _: TypeFuncRef => BoxFunc(None)
case _: TypeStackRef => BoxStack(None)
case _: TypeThreadRef => BoxThread(None)
case _: TypeFrameCursorRef => BoxFrameCursor(None)
case _: TypeIRBuilderRef => BoxIRBuilder(None)
case _: TypeFuncRef => BoxOpaque[Function](None)
case _: TypeStackRef => BoxOpaque[InterpreterStack](None)
case _: TypeThreadRef => BoxOpaque[InterpreterThread](None)
case _: TypeFrameCursorRef => BoxOpaque[FrameCursor](None)
case _: TypeIRBuilderRef => BoxOpaque[IRBuilder](None)
}
}
\ No newline at end of file
......@@ -11,6 +11,10 @@ import uvm.ssavariables._
import uvm.ssavariables.AtomicRMWOptr._
import uvm.types._
import uvm.IRNode
import uvm.Function
import uvm.refimpl.mem.EntityAccessors.CanBeIntegerized
import uvm.ir.irbuilder.IRBuilder
import uvm.refimpl.mem.EntityAccessors._
object OpHelper {
......@@ -382,25 +386,20 @@ object MemoryOperations {
noAccessViaPointer(ptr, ty)
val raw = memorySupport.loadLong(loc)
br.asInstanceOf[BoxTagRef64].raw = raw
case _: TypeFuncRef =>
noAccessViaPointer(ptr, ty)
val fid = memorySupport.loadLong(loc).toInt
val func = microVM.globalBundle.funcNs.get(fid)
br.asInstanceOf[BoxFunc].func = func
case _: TypeThreadRef =>
noAccessViaPointer(ptr, ty)
val tid = memorySupport.loadLong(loc).toInt
val thr = microVM.threadStackManager.threadRegistry.get(tid)
br.asInstanceOf[BoxThread].thread = thr
case _: TypeStackRef =>
noAccessViaPointer(ptr, ty)
val sid = memorySupport.loadLong(loc).toInt
val sta = microVM.threadStackManager.stackRegistry.get(sid)
br.asInstanceOf[BoxStack].stack = sta
case _: TypeIRNodeRef =>
case _: AbstractOpaqueRefType => {
def loadEntity[T: CanBeIntegerized](): Unit = {
val obj = memorySupport.loadEntity[T](loc)
br.asInstanceOf[BoxOpaque[T]].obj = obj
}
noAccessViaPointer(ptr, ty)
val maybeIRNode = loadIRNode(loc)
br.asInstanceOf[BoxIRNode].node = maybeIRNode
ty match {
case _: TypeFuncRef => loadEntity[Function]()
case _: TypeThreadRef => loadEntity[InterpreterThread]()
case _: TypeStackRef => loadEntity[InterpreterStack]()
case _: TypeFrameCursorRef => loadEntity[FrameCursor]()
case _: TypeIRBuilderRef => loadEntity[IRBuilder]()
}
}
case _ => throw new UvmUnimplementedOperationException("Loading of type %s is not supporing".format(ty.getClass.getName))
}
......@@ -452,22 +451,20 @@ object MemoryOperations {
noAccessViaPointer(ptr, ty)
val raw = nvb.asInstanceOf[BoxTagRef64].raw
memorySupport.storeLong(loc, raw)
case _: TypeFuncRef =>
noAccessViaPointer(ptr, ty)
val fid = nvb.asInstanceOf[BoxFunc].func.map(_.id).getOrElse(0)
memorySupport.storeLong(loc, fid.toLong & 0xFFFFFFFFL)
case _: TypeThreadRef =>
noAccessViaPointer(ptr, ty)
val tid = nvb.asInstanceOf[BoxThread].thread.map(_.id).getOrElse(0)
memorySupport.storeLong(loc, tid.toLong & 0xFFFFFFFFL)
case _: TypeStackRef =>
noAccessViaPointer(ptr, ty)
val sid = nvb.asInstanceOf[BoxStack].stack.map(_.id).getOrElse(0)
memorySupport.storeLong(loc, sid.toLong & 0xFFFFFFFFL)
case _: TypeIRNodeRef =>
case _: AbstractOpaqueRefType => {
def storeEntity[T: CanBeIntegerized](): Unit = {
val obj = nvb.asInstanceOf[BoxOpaque[T]].obj
memorySupport.storeEntity[T](loc, obj)
}
noAccessViaPointer(ptr, ty)
val maybeIRNode = nvb.asInstanceOf[BoxIRNode].node
storeIRNode(loc, maybeIRNode)
ty match {
case _: TypeFuncRef => storeEntity[Function]()
case _: TypeThreadRef => storeEntity[InterpreterThread]()
case _: TypeStackRef => storeEntity[InterpreterStack]()
case _: TypeFrameCursorRef => storeEntity[FrameCursor]()
case _: TypeIRBuilderRef => storeEntity[IRBuilder]()
}
}
case _ => throw new UvmUnimplementedOperationException("Storing of type %s is not supporing".format(ty.getClass.getName))
}
......@@ -523,30 +520,23 @@ object MemoryOperations {
val (succ, (rl, rh)) = memorySupport.cmpXchgI128(loc, (el, eh), (dl, dh))
br.asInstanceOf[BoxIRef].oo = (rl, rh)
succ
case _: TypeFuncRef =>
noAccessViaPointer(ptr, ty)
val el = eb.asInstanceOf[BoxFunc].func.map(_.id).getOrElse(0).toLong
val dl = db.asInstanceOf[BoxFunc].func.map(_.id).getOrElse(0).toLong
val (succ, rl) = memorySupport.cmpXchgLong(loc, el, dl)
val rf = microVM.globalBundle.funcNs.get(rl.toInt)
br.asInstanceOf[BoxFunc].func = rf
succ
case _: TypeThreadRef =>
noAccessViaPointer(ptr, ty)
val el = eb.asInstanceOf[BoxThread].thread.map(_.id).getOrElse(0).toLong
val dl = db.asInstanceOf[BoxThread].thread.map(_.id).getOrElse(0).toLong
val (succ, rl) = memorySupport.cmpXchgLong(loc, el, dl)
val rt = microVM.threadStackManager.threadRegistry.get(rl.toInt)
br.asInstanceOf[BoxThread].thread = rt
succ
case _: TypeStackRef =>
case _: AbstractOpaqueRefType => {
def cmpXchgEntity[T: CanBeIntegerized](): Boolean = {
val eObj = eb.asInstanceOf[BoxOpaque[T]].obj
val dObj = db.asInstanceOf[BoxOpaque[T]].obj
val (succ, rObj) = memorySupport.cmpXchgEntity(loc, eObj, dObj)
br.asInstanceOf[BoxOpaque[T]].obj = rObj
succ
}
noAccessViaPointer(ptr, ty)
val el = eb.asInstanceOf[BoxStack].stack.map(_.id).getOrElse(0).toLong
val dl = db.asInstanceOf[BoxStack].stack.map(_.id).getOrElse(0).toLong
val (succ, rl) = memorySupport.cmpXchgLong(loc, el, dl)
val rs = microVM.threadStackManager.stackRegistry.get(rl.toInt)
br.asInstanceOf[BoxStack].stack = rs
succ
ty match {
case _: TypeFuncRef => cmpXchgEntity[Function]()
case _: TypeThreadRef => cmpXchgEntity[InterpreterThread]()
case _: TypeStackRef => cmpXchgEntity[InterpreterStack]()
case _: TypeFrameCursorRef => cmpXchgEntity[FrameCursor]()
case _: TypeIRBuilderRef => cmpXchgEntity[IRBuilder]()
}
}
case _ => throw new UvmUnimplementedOperationException("CmpXchg of type %s is not supporing".format(ty.getClass.getName))
}
}
......@@ -580,29 +570,21 @@ object MemoryOperations {
val BoxIRef(ol, oh) = ob.asInstanceOf[BoxIRef]
val (rl, rh) = memorySupport.xchgI128(loc, (ol, oh))
br.asInstanceOf[BoxIRef].oo = (rl, rh)
case _: TypeFuncRef =>
noAccessViaPointer(ptr, ty)
val ol = ob.asInstanceOf[BoxFunc].func.map(_.id).getOrElse(0).toLong
val rl = memorySupport.atomicRMWLong(op, loc, ol)
val rf = microVM.globalBundle.funcNs.get(rl.toInt)
br.asInstanceOf[BoxFunc].func = rf
case _: TypeThreadRef =>
noAccessViaPointer(ptr, ty)
val ol = ob.asInstanceOf[BoxThread].thread.map(_.id).getOrElse(0).toLong
val rl = memorySupport.atomicRMWLong(op, loc, ol)
val rt = microVM.threadStackManager.threadRegistry.get(rl.toInt)
br.asInstanceOf[BoxThread].thread = rt
case _: TypeStackRef =>
case _: AbstractOpaqueRefType => {
def xchgEntity[T: CanBeIntegerized](): Unit = {
val obj = ob.asInstanceOf[BoxOpaque[T]].obj
val oldObj = memorySupport.xchgEntity(loc, obj)
br.asInstanceOf[BoxOpaque[T]].obj = oldObj
}
noAccessViaPointer(ptr, ty)
val ol = ob.asInstanceOf[BoxStack].stack.map(_.id).getOrElse(0).toLong
val rl = memorySupport.atomicRMWLong(op, loc, ol)
val rs = microVM.threadStackManager.stackRegistry.get(rl.toInt)
br.asInstanceOf[BoxStack].stack = rs
case _: TypeTagRef64 =>
noAccessViaPointer(ptr, ty)
val ol = ob.asInstanceOf[BoxTagRef64].raw
val rl = memorySupport.atomicRMWLong(op, loc, ol)
br.asInstanceOf[BoxTagRef64].raw = rl
ty match {
case _: TypeFuncRef => xchgEntity[Function]()
case _: TypeThreadRef => xchgEntity[InterpreterThread]()
case _: TypeStackRef => xchgEntity[InterpreterStack]()
case _: TypeFrameCursorRef => xchgEntity[FrameCursor]()
case _: TypeIRBuilderRef => xchgEntity[IRBuilder]()
}
}
case _ =>
throw new UvmUnimplementedOperationException("AtomicRMW XCHG of type %s is not supporing".format(ty.getClass.getName))
}
......@@ -660,19 +642,19 @@ object MemoryOperations {
loc
}
/**
* Load irnoderef value from the memory. Use fake value from microVM.irNodeRegistry
*/
def loadIRNode(loc: Word)(implicit microVM: MicroVM, memorySupport: MemorySupport): Option[IRNode] = {
memorySupport.loadEntity[IRNode](loc)
def loadIRBuilder(loc: Word)(implicit microVM: MicroVM, memorySupport: MemorySupport): Option[IRBuilder] = {
memorySupport.loadEntity[IRBuilder](loc)
}
/**
* Store irnoderef value into the memory. Use fake value from microVM.irNodeRegistry
*/
def storeIRNode(loc: Word, maybeIRNode: Option[IRNode])(implicit microVM: MicroVM, memorySupport: MemorySupport): Unit = {
memorySupport.storeEntity(loc, maybeIRNode)
def storeIRBuilder(loc: Word, maybeIRBuilder: Option[IRBuilder])(implicit microVM: MicroVM, memorySupport: MemorySupport): Unit = {
memorySupport.storeEntity(loc, maybeIRBuilder)
}
def loadInt32Array(base: Word, len: Word)(implicit memorySupport: MemorySupport): IndexedSeq[Int] = {
......@@ -698,16 +680,5 @@ object MemoryOperations {