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.

ssavariables.scala 10.3 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1
2
3
4
5
6
package uvm.ssavariables

import uvm._
import uvm.comminsts._
import uvm.types._

7
8
abstract class SSAVariable extends IdentifiedSettable {
  override def hashCode(): Int = id
9
10
  override def equals(that: Any): Boolean = that match {
    case v: AnyRef => this eq v
11
    case _         => false
12
  }
Kunshan Wang's avatar
Kunshan Wang committed
13
  override def toString = "%s%s".format(this.getClass.getSimpleName, this.repr)
14
}
Kunshan Wang's avatar
Kunshan Wang committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

// Global variables: Constants, Global Cells and Functions (Function is defined in controlFlow.scala)

abstract class GlobalVariable extends SSAVariable

abstract class Constant extends GlobalVariable {
  var constTy: Type
}

case class ConstInt(var constTy: Type, var num: BigInt) extends Constant

case class ConstFloat(var constTy: Type, var num: Float) extends Constant

case class ConstDouble(var constTy: Type, var num: Double) extends Constant

case class ConstStruct(var constTy: Type, var fields: Seq[GlobalVariable]) extends Constant

Kunshan Wang's avatar
Kunshan Wang committed
32
33
case class ConstArray(var constTy: Type, var elems: Seq[GlobalVariable]) extends Constant

Kunshan Wang's avatar
Kunshan Wang committed
34
35
case class ConstNull(var constTy: Type) extends Constant

Kunshan Wang's avatar
Kunshan Wang committed
36
37
case class ConstVector(var constTy: Type, var elems: Seq[Constant]) extends Constant

38
39
case class ConstPointer(var constTy: Type, var addr: Long) extends Constant

Kunshan Wang's avatar
Kunshan Wang committed
40
41
case class GlobalCell(var cellTy: Type) extends GlobalVariable

42
case class ExposedFunc(var func: Function, var callConv: Flag, var cookie: ConstInt) extends GlobalVariable
43

Kunshan Wang's avatar
Kunshan Wang committed
44
45
// Local variables: Parameters and Instructions

Kunshan Wang's avatar
Kunshan Wang committed
46
abstract class LocalVariable extends SSAVariable
Kunshan Wang's avatar
Kunshan Wang committed
47

Kunshan Wang's avatar
Kunshan Wang committed
48
49
50
abstract class Parameter extends LocalVariable
case class NorParam(ty: Type) extends Parameter
case class ExcParam() extends Parameter
Kunshan Wang's avatar
Kunshan Wang committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

// Instructions

abstract class Instruction extends LocalVariable

/// enumerations

object BinOptr extends Enumeration {
  type BinOptr = Value
  val ADD, SUB, MUL, UDIV, SDIV, UREM, SREM, SHL, LSHR, ASHR, AND, OR, XOR = Value
  val FADD, FSUB, FMUL, FDIV, FREM = Value
}

import uvm.ssavariables.BinOptr.BinOptr

object CmpOptr extends Enumeration {
  type CmpOptr = Value
  val EQ, NE, ULT, ULE, UGT, UGE, SLT, SLE, SGT, SGE = Value
  val FTRUE, FFALSE, FORD, FOEQ, FONE, FOLT, FOLE, FOGT, FOGE = Value
  val FUNO, FUEQ, FUNE, FULT, FULE, FUGT, FUGE = Value
}

import uvm.ssavariables.CmpOptr.CmpOptr

object ConvOptr extends Enumeration {
  type ConvOptr = Value
77
  val TRUNC, ZEXT, SEXT, FPTRUNC, FPEXT, FPTOUI, FPTOSI, UITOFP, SITOFP, BITCAST, REFCAST, PTRCAST = Value
Kunshan Wang's avatar
Kunshan Wang committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
}

import uvm.ssavariables.ConvOptr.ConvOptr

object MemoryOrder extends Enumeration {
  type MemoryOrder = Value
  val NOT_ATOMIC, RELAXED, CONSUME, ACQUIRE, RELEASE, ACQ_REL, SEQ_CST = Value
}

import uvm.ssavariables.MemoryOrder.MemoryOrder

object AtomicRMWOptr extends Enumeration {
  type AtomicRMWOptr = Value
  val XCHG, ADD, SUB, AND, NAND, OR, XOR, MIN, MAX, UMIN, UMAX = Value
}

import uvm.ssavariables.AtomicRMWOptr.AtomicRMWOptr

/// Abstract instructions and traits

trait HasTypeList extends Instruction {
  var typeList: Seq[Type]
}

trait HasArgList extends Instruction {
  var argList: Seq[SSAVariable]
}

trait CallLike extends HasArgList {
  var sig: FuncSig
  var callee: SSAVariable
}

Kunshan Wang's avatar
Kunshan Wang committed
111
112
113
case class DestClause(val bb: BasicBlock, val args: Seq[SSAVariable])

case class ExcClause(val nor: DestClause, val exc: DestClause)
Kunshan Wang's avatar
Kunshan Wang committed
114
115
116
117
118
119

trait HasExcClause extends Instruction {
  var excClause: Option[ExcClause]
}

trait HasKeepAliveClause extends Instruction {
Kunshan Wang's avatar
Kunshan Wang committed
120
  var keepAlives: Seq[LocalVariable]
Kunshan Wang's avatar
Kunshan Wang committed
121
122
123
124
125
126
}

abstract class AbstractCall extends CallLike

abstract class AbstractRet extends Instruction

Kunshan Wang's avatar
Kunshan Wang committed
127
abstract class AbstractAlloc extends HasExcClause {
Kunshan Wang's avatar
Kunshan Wang committed
128
129
130
131
132
133
  def allocTy: Type
}

trait FixedAlloc extends AbstractAlloc

trait HybridAlloc extends AbstractAlloc {
Kunshan Wang's avatar
Kunshan Wang committed
134
  def lenTy: TypeInt
Kunshan Wang's avatar
Kunshan Wang committed
135
136
137
138
139
140
141
  def length: SSAVariable
}

abstract class HeapAlloc extends AbstractAlloc

abstract class StackAlloc extends AbstractAlloc

142
143
144
145
trait WorksWithPointer extends Instruction {
  var ptr: Boolean
}

Kunshan Wang's avatar
Kunshan Wang committed
146
147
148
149
150
151
152
153
154
abstract class AbstractTrap extends HasKeepAliveClause {
  var retTy: Type
}

abstract class CurStackAction
case class RetWith(var retTy: Type) extends CurStackAction
case class KillOld() extends CurStackAction

abstract class NewStackAction
Kunshan Wang's avatar
Kunshan Wang committed
155
case class PassValue(var argTy: Type, var arg: SSAVariable) extends NewStackAction
Kunshan Wang's avatar
Kunshan Wang committed
156
157
case class ThrowExc(var exc: SSAVariable) extends NewStackAction

158
159
160
161
162
/**
 * Flags are used in common instructions.
 */
case class Flag(name: String)

Kunshan Wang's avatar
Kunshan Wang committed
163
164
165
166
167
168
169
170
/// Concrete instructions
case class InstBinOp(var op: BinOptr, var opndTy: Type, var op1: SSAVariable, var op2: SSAVariable,
                     var excClause: Option[ExcClause]) extends HasExcClause

case class InstCmp(var op: CmpOptr, var opndTy: Type, var op1: SSAVariable, var op2: SSAVariable) extends Instruction

case class InstConv(var op: ConvOptr, var fromTy: Type, var toTy: Type, var opnd: SSAVariable) extends Instruction

171
case class InstSelect(var condTy: Type, var opndTy: Type,
Kunshan Wang's avatar
Kunshan Wang committed
172
173
                      var cond: SSAVariable, var ifTrue: SSAVariable, var ifFalse: SSAVariable) extends Instruction

Kunshan Wang's avatar
Kunshan Wang committed
174
case class InstBranch(var dest: DestClause) extends Instruction
Kunshan Wang's avatar
Kunshan Wang committed
175

Kunshan Wang's avatar
Kunshan Wang committed
176
case class InstBranch2(var cond: SSAVariable, var ifTrue: DestClause, var ifFalse: DestClause) extends Instruction
Kunshan Wang's avatar
Kunshan Wang committed
177

Kunshan Wang's avatar
Kunshan Wang committed
178
179
case class InstSwitch(var opndTy: Type, var opnd: SSAVariable, var defDest: DestClause,
                      var cases: Seq[(SSAVariable, DestClause)]) extends Instruction
Kunshan Wang's avatar
Kunshan Wang committed
180
181

case class InstCall(var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable],
182
                    var excClause: Option[ExcClause], var keepAlives: Seq[LocalVariable]) extends AbstractCall with HasExcClause with HasKeepAliveClause
Kunshan Wang's avatar
Kunshan Wang committed
183
184
185

case class InstTailCall(var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable]) extends AbstractCall

Kunshan Wang's avatar
Kunshan Wang committed
186
case class InstRet(val funcVer: FuncVer, var retVal: SSAVariable) extends AbstractRet
Kunshan Wang's avatar
Kunshan Wang committed
187
188
189
190
191

case class InstRetVoid() extends AbstractRet

case class InstThrow(var excVal: SSAVariable) extends Instruction

Kunshan Wang's avatar
Kunshan Wang committed
192
case class InstExtractValue(var strTy: TypeStruct, var index: Int, var opnd: SSAVariable) extends Instruction
Kunshan Wang's avatar
Kunshan Wang committed
193

Kunshan Wang's avatar
Kunshan Wang committed
194
case class InstInsertValue(var strTy: TypeStruct, var index: Int, var opnd: SSAVariable, var newVal: SSAVariable) extends Instruction
Kunshan Wang's avatar
Kunshan Wang committed
195

Kunshan Wang's avatar
Kunshan Wang committed
196
case class InstExtractElement(var seqTy: AbstractSeqType, var indTy: TypeInt,
Kunshan Wang's avatar
Kunshan Wang committed
197
198
                              var opnd: SSAVariable, var index: SSAVariable) extends Instruction

Kunshan Wang's avatar
Kunshan Wang committed
199
case class InstInsertElement(var seqTy: AbstractSeqType, var indTy: TypeInt,
Kunshan Wang's avatar
Kunshan Wang committed
200
201
                             var opnd: SSAVariable, var index: SSAVariable, var newVal: SSAVariable) extends Instruction

Kunshan Wang's avatar
Kunshan Wang committed
202
case class InstShuffleVector(var vecTy: TypeVector, var maskTy: TypeVector,
Kunshan Wang's avatar
Kunshan Wang committed
203
204
                             var vec1: SSAVariable, var vec2: SSAVariable, var mask: SSAVariable) extends Instruction

Kunshan Wang's avatar
Kunshan Wang committed
205
case class InstNew(var allocTy: Type, var excClause: Option[ExcClause]) extends HeapAlloc with FixedAlloc
Kunshan Wang's avatar
Kunshan Wang committed
206

Kunshan Wang's avatar
Kunshan Wang committed
207
case class InstNewHybrid(var allocTy: TypeHybrid, var lenTy: TypeInt, var length: SSAVariable, var excClause: Option[ExcClause]) extends HeapAlloc with HybridAlloc
Kunshan Wang's avatar
Kunshan Wang committed
208

Kunshan Wang's avatar
Kunshan Wang committed
209
case class InstAlloca(var allocTy: Type, var excClause: Option[ExcClause]) extends StackAlloc with FixedAlloc
Kunshan Wang's avatar
Kunshan Wang committed
210

Kunshan Wang's avatar
Kunshan Wang committed
211
case class InstAllocaHybrid(var allocTy: TypeHybrid, var lenTy: TypeInt, var length: SSAVariable, var excClause: Option[ExcClause]) extends StackAlloc with HybridAlloc
Kunshan Wang's avatar
Kunshan Wang committed
212
213
214

case class InstGetIRef(var referentTy: Type, var opnd: SSAVariable) extends Instruction

215
case class InstGetFieldIRef(var ptr: Boolean, var referentTy: TypeStruct, var index: Int, var opnd: SSAVariable) extends WorksWithPointer
Kunshan Wang's avatar
Kunshan Wang committed
216

217
218
case class InstGetElemIRef(var ptr: Boolean, var referentTy: AbstractSeqType, var indTy: TypeInt,
                           var opnd: SSAVariable, var index: SSAVariable) extends WorksWithPointer
Kunshan Wang's avatar
Kunshan Wang committed
219

220
221
case class InstShiftIRef(var ptr: Boolean, var referentTy: Type, var offTy: TypeInt,
                         var opnd: SSAVariable, var offset: SSAVariable) extends WorksWithPointer
Kunshan Wang's avatar
Kunshan Wang committed
222

223
case class InstGetFixedPartIRef(var ptr: Boolean, var referentTy: TypeHybrid, var opnd: SSAVariable) extends WorksWithPointer
Kunshan Wang's avatar
Kunshan Wang committed
224

225
case class InstGetVarPartIRef(var ptr: Boolean, var referentTy: TypeHybrid, var opnd: SSAVariable) extends WorksWithPointer
Kunshan Wang's avatar
Kunshan Wang committed
226

227
case class InstLoad(var ptr: Boolean, var ord: MemoryOrder, var referentTy: Type, var loc: SSAVariable, var excClause: Option[ExcClause]) extends WorksWithPointer with HasExcClause
Kunshan Wang's avatar
Kunshan Wang committed
228

229
case class InstStore(var ptr: Boolean, var ord: MemoryOrder, var referentTy: Type, var loc: SSAVariable, var newVal: SSAVariable, var excClause: Option[ExcClause]) extends WorksWithPointer with HasExcClause
Kunshan Wang's avatar
Kunshan Wang committed
230

231
232
case class InstCmpXchg(var ptr: Boolean, var weak: Boolean, var ordSucc: MemoryOrder, var ordFail: MemoryOrder, var referentTy: Type,
                       var loc: SSAVariable, var expected: SSAVariable, var desired: SSAVariable, var excClause: Option[ExcClause]) extends WorksWithPointer with HasExcClause
Kunshan Wang's avatar
Kunshan Wang committed
233

234
235
case class InstAtomicRMW(var ptr: Boolean, var ord: MemoryOrder, var op: AtomicRMWOptr,
                         var referentTy: Type, var loc: SSAVariable, var opnd: SSAVariable, var excClause: Option[ExcClause]) extends WorksWithPointer with HasExcClause
Kunshan Wang's avatar
Kunshan Wang committed
236
237

case class InstFence(var ord: MemoryOrder) extends Instruction
Kunshan Wang's avatar
Kunshan Wang committed
238

239
case class InstTrap(var retTy: Type, var excClause: Option[ExcClause], var keepAlives: Seq[LocalVariable]) extends AbstractTrap with HasExcClause
Kunshan Wang's avatar
Kunshan Wang committed
240
241

case class InstWatchPoint(var wpID: Int, var retTy: Type,
Kunshan Wang's avatar
Kunshan Wang committed
242
                          var dis: DestClause, var ena: DestClause, var exc: Option[DestClause],
Kunshan Wang's avatar
Kunshan Wang committed
243
                          var keepAlives: Seq[LocalVariable]) extends AbstractTrap
Kunshan Wang's avatar
Kunshan Wang committed
244

245
246
case class InstCCall(var callConv: Flag, var funcTy: Type,
                     var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable], var keepAlives: Seq[LocalVariable]) extends CallLike with HasKeepAliveClause
Kunshan Wang's avatar
Kunshan Wang committed
247
248
249
250
251

case class InstNewStack(var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable],
                        var excClause: Option[ExcClause]) extends CallLike with HasExcClause

case class InstSwapStack(var swappee: SSAVariable, var curStackAction: CurStackAction, var newStackAction: NewStackAction,
Kunshan Wang's avatar
Kunshan Wang committed
252
                         var excClause: Option[ExcClause], var keepAlives: Seq[LocalVariable]) extends HasExcClause with HasKeepAliveClause
Kunshan Wang's avatar
Kunshan Wang committed
253

254
case class InstCommInst(var inst: CommInst, var flagList: Seq[Flag], var typeList: Seq[Type], var funcSigList: Seq[FuncSig], var argList: Seq[SSAVariable],
Kunshan Wang's avatar
Kunshan Wang committed
255
                        var excClause: Option[ExcClause], var keepAlives: Seq[LocalVariable])
256
    extends HasTypeList with HasArgList with HasExcClause with HasKeepAliveClause