WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

boxes.scala 4.24 KB
Newer Older
1
2
3
package uvm.refimpl.itpr

import uvm._
Kunshan Wang's avatar
Kunshan Wang committed
4
5
import uvm.types._
import uvm.refimpl._
6
7
import uvm.refimpl.mem.TypeSizes.Word

Kunshan Wang's avatar
Kunshan Wang committed
8
9
10
abstract class ValueBox {
  def copyFrom(other: ValueBox): Unit
}
11

12
13
14
15
16
17
abstract class HasObjRef extends ValueBox {
  def hasObjRef(): Boolean
  def getObjRef(): Word
  def setObjRef(newObjRef: Word): Unit
}

Kunshan Wang's avatar
Kunshan Wang committed
18
19
20
21
22
23
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 }
}
24

Kunshan Wang's avatar
Kunshan Wang committed
25
26
27
28
29
30
31
32
33
34
35
36
case class BoxInt(var value: BigInt) extends ValueBox {
  def copyFrom(other: ValueBox): Unit = { this.value = other.asInstanceOf[BoxInt].value }
}
case class BoxFloat(var value: Float) extends ValueBox {
  def copyFrom(other: ValueBox): Unit = { this.value = other.asInstanceOf[BoxFloat].value }
}
case class BoxDouble(var value: Double) extends ValueBox {
  def copyFrom(other: ValueBox): Unit = { this.value = other.asInstanceOf[BoxDouble].value }
}
case class BoxVector(var values: Seq[ValueBox]) extends ValueBox {
  def copyFrom(other: ValueBox): Unit = { for ((t, o) <- this.values.zip(other.asInstanceOf[BoxVector].values)) t.copyFrom(o) }
}
37
case class BoxRef(var objRef: Word) extends HasObjRef {
Kunshan Wang's avatar
Kunshan Wang committed
38
  def copyFrom(other: ValueBox): Unit = { this.objRef = other.asInstanceOf[BoxRef].objRef }
39
40
41
42
43
  def hasObjRef() = true
  def getObjRef() = objRef
  def setObjRef(newObjRef: Word): Unit = { objRef = newObjRef }
}
case class BoxIRef(var objRef: Word, var offset: Word) extends HasObjRef {
Kunshan Wang's avatar
Kunshan Wang committed
44
45
46
47
  def copyFrom(other: ValueBox): Unit = {
    val that = other.asInstanceOf[BoxIRef]
    this.objRef = that.objRef; this.offset = that.offset
  }
48
49
50
  def hasObjRef() = objRef != 0
  def getObjRef() = objRef
  def setObjRef(newObjRef: Word): Unit = { objRef = newObjRef }
51
52
53
54
  
  // Helper to get and set the objRef and offset at the same time
  def oo: (Word, Word) = (objRef, offset)
  def oo_=(newVal: (Word, Word)): Unit = { objRef = newVal._1; offset = newVal._2 }
55
}
Kunshan Wang's avatar
Kunshan Wang committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
case class BoxStruct(var values: Seq[ValueBox]) extends ValueBox {
  def copyFrom(other: ValueBox): Unit = { for ((t, o) <- this.values.zip(other.asInstanceOf[BoxStruct].values)) t.copyFrom(o) }
}
case class BoxVoid() extends ValueBox {
  def copyFrom(other: ValueBox): Unit = {}
}
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 }
}
74
case class BoxTagRef64(var raw: Long) extends HasObjRef {
Kunshan Wang's avatar
Kunshan Wang committed
75
  def copyFrom(other: ValueBox): Unit = { this.raw = other.asInstanceOf[BoxTagRef64].raw }
76
77
78
79
80
81
  def hasObjRef() = OpHelper.tr64IsRef(raw)
  def getObjRef() = OpHelper.tr64ToRef(raw)
  def setObjRef(newObjRef: Word) = {
    val oldTag = OpHelper.tr64ToTag(raw)
    raw = OpHelper.refToTr64(newObjRef, oldTag)
  }
82
}
83
84
85
86
87
88
case class BoxPointer(var addr: Word) extends ValueBox {
  def copyFrom(other: ValueBox): Unit = {
    val that = other.asInstanceOf[BoxPointer]
    this.addr = that.addr
  }
}
89

Kunshan Wang's avatar
Kunshan Wang committed
90
91
92
93
94
95
object ValueBox {

  def makeBoxForType(ty: Type): ValueBox = ty match {
    case _: TypeInt => BoxInt(0)
    case _: TypeFloat => BoxFloat(0.0f)
    case _: TypeDouble => BoxDouble(0.0d)
Kunshan Wang's avatar
Kunshan Wang committed
96
    case TypeVector(elemTy, len) => BoxVector(Seq.fill(len.toInt)(makeBoxForType(elemTy)))
Kunshan Wang's avatar
Kunshan Wang committed
97
98
99
100
101
102
103
104
105
106
107
    case _: TypeRef => BoxRef(0L)
    case _: TypeIRef => BoxIRef(0L, 0L)
    case _: TypeWeakRef => throw new UvmRefImplException("weakref cannot be an SSA variable type")
    case TypeStruct(fieldTys) => BoxStruct(fieldTys.map(makeBoxForType))
    case _: TypeArray => throw new UvmRefImplException("array cannot be an SSA variable type")
    case _: TypeHybrid => throw new UvmRefImplException("hybrid cannot be an SSA variable type")
    case _: TypeVoid => BoxVoid()
    case _: TypeFunc => BoxFunc(None)
    case _: TypeStack => BoxStack(None)
    case _: TypeThread => BoxThread(None)
    case _: TypeTagRef64 => BoxTagRef64(0L)
108
109
    case _: TypePtr => BoxPointer(0L)
    case _: TypeFuncPtr => BoxPointer(0L)
Kunshan Wang's avatar
Kunshan Wang committed
110
111
112
  }

}