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.

TestingBundlesValidators.scala 38.3 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1
2
package uvm.ir.textinput

Kunshan Wang's avatar
Kunshan Wang committed
3
4
5
6
import org.scalatest._

import uvm._
import uvm.types._
Kunshan Wang's avatar
Kunshan Wang committed
7
8
import uvm.ssavariables._
import uvm.comminsts._
Kunshan Wang's avatar
Kunshan Wang committed
9
import UIRTextReader.globalize
Kunshan Wang's avatar
Kunshan Wang committed
10
11
12
13

trait TestingBundlesValidators extends Matchers with ExtraMatchers {
  
  implicit class MagicalOur(b: Bundle) {
Kunshan Wang's avatar
Kunshan Wang committed
14
15
16
17
18
19
20
21
    def ty(s: String) = b.typeNs(s)
    def const(s: String) = b.constantNs (s)
    def value(s: String) = b.varNs(s)
    def globalValue(s: String) = b.globalVarNs(s)
    def globalCell(s: String) = b.globalCellNs(s)
    def sig(s: String) = b.funcSigNs(s)
    def func(s: String) = b.funcNs(s)
    def funcVer(s: String) = b.funcVerNs(s)
Kunshan Wang's avatar
Kunshan Wang committed
22
23
  }

Kunshan Wang's avatar
Kunshan Wang committed
24
25
26
27
28
29
  implicit class MagicalMy(c: FuncVer) {
    def globalName(s: String) = UIRTextReader.globalize(s, c.name.get)
    def bb(s: String) = c.bbNs(UIRTextReader.globalize(s, c.name.get))
    def value(s: String) = c.localVarNs(UIRTextReader.globalize(s, c.name.get))
    def param(s: String) = c.localVarNs(UIRTextReader.globalize(s, c.name.get))
    def inst(s: String) = c.localVarNs(UIRTextReader.globalize(s, c.name.get))
Kunshan Wang's avatar
Kunshan Wang committed
30
31
  }

Kunshan Wang's avatar
Kunshan Wang committed
32
33
34
  def validateTypes(bundle: Bundle) {
    val our = bundle
    
Kunshan Wang's avatar
Kunshan Wang committed
35
36
37
38
39
    our ty "@i1" shouldBeATypeIntOf(1)
    our ty "@i8" shouldBeATypeIntOf(8)
    our ty "@i16" shouldBeATypeIntOf(16)
    our ty "@i32" shouldBeATypeIntOf(32)
    our ty "@i64" shouldBeATypeIntOf(64)
Kunshan Wang's avatar
Kunshan Wang committed
40
    
Kunshan Wang's avatar
Kunshan Wang committed
41
42
    our ty "@float" shouldBeA[TypeFloat] thatsIt
    our ty "@double" shouldBeA[TypeDouble] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
43
    
Kunshan Wang's avatar
Kunshan Wang committed
44
45
46
    our ty "@rv" shouldBeA[TypeRef] { _.ty shouldBe (our ty "@void") }
    our ty "@irv" shouldBeA[TypeIRef] { _.ty shouldBe (our ty "@void") }
    our ty "@wrv" shouldBeA[TypeWeakRef] { _.ty shouldBe (our ty "@void") }
Kunshan Wang's avatar
Kunshan Wang committed
47
    
Kunshan Wang's avatar
Kunshan Wang committed
48
    our ty "@ri16" shouldBeA[TypeRef] { _.ty shouldBe (our ty "@i16")}
Kunshan Wang's avatar
Kunshan Wang committed
49
50

    our ty "@s1" shouldBeA[TypeStruct] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
51
52
53
54
55
56
57
58
59
60
      its fieldTy 0 shouldBe (our ty "@i8")
      its fieldTy 1 shouldBe (our ty "@i16")
      its fieldTy 2 shouldBe (our ty "@i32")
      its fieldTy 3 shouldBe (our ty "@i64")
      its fieldTy 4 shouldBe (our ty "@float")
      its fieldTy 5 shouldBe (our ty "@double")
      its fieldTy 6 shouldBe (our ty "@rv")
      its fieldTy 7 shouldBe (our ty "@irv")
      its fieldTy 8 shouldBe (our ty "@wrv")
      its fieldTy 9 shouldBe (our ty "@ri16")
Kunshan Wang's avatar
Kunshan Wang committed
61
62
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
63
64
65
    our ty "@Cons" shouldBeA[TypeStruct] { its =>
      its fieldTy 0 shouldBe (our ty "@i64")
      its fieldTy 1 shouldBe (our ty "@RefCons")
Kunshan Wang's avatar
Kunshan Wang committed
66
67
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
68
69
70
71
72
73
74
    our ty "@RefCons" shouldBeA[TypeRef] { _.ty should be (our ty "@Cons") }

    our ty "@foo" shouldBeA[TypeStruct] { its =>
      its fieldTy 0 shouldBe (our ty "@double")
      its fieldTy 1 shouldBe (our ty "@i64")
    }

Kunshan Wang's avatar
Kunshan Wang committed
75
    our ty "@a0" shouldBeA[TypeArray] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
76
      its.elemTy shouldBe (our ty "@i8")
Kunshan Wang's avatar
Kunshan Wang committed
77
78
79
      its.len shouldEqual 100
    }
    our ty "@a1" shouldBeA[TypeArray] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
80
      its.elemTy shouldBe (our ty "@foo")
Kunshan Wang's avatar
Kunshan Wang committed
81
82
83
84
85
86
87
88
      its.len shouldEqual 10
    }
    our ty "@a2" shouldBeA[TypeArray] { its =>
      its.elemTy shouldBe (our ty "@a1")
      its.len shouldEqual 10
    }
    
    our ty "@h0" shouldBeA[TypeHybrid] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
89
90
      its.fixedTy shouldBe (our ty "@void")
      its.varTy shouldBe (our ty "@i8")
Kunshan Wang's avatar
Kunshan Wang committed
91
92
    }
    our ty "@h1" shouldBeA[TypeHybrid] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
93
94
      its.fixedTy shouldBe (our ty "@foo")
      its.varTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
95
96
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
97
    our ty "@void" shouldBeA[TypeVoid] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
98
    
Kunshan Wang's avatar
Kunshan Wang committed
99
100
101
    our sig "@sig0" shouldBeA[FuncSig] { its =>
      its.retTy shouldBe (our ty "@void")
      its.paramTy shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
102
    }
Kunshan Wang's avatar
Kunshan Wang committed
103
104
105
106
107
108
109
110
    
    our ty "@ii8" shouldBeA[TypeIRef] { _.ty shouldBe (our ty "@i8") }
    our ty "@iii8" shouldBeA[TypeIRef] { _.ty shouldBe (our ty "@ii8") }
    
    our sig "@sig1" shouldBeA[FuncSig] { its =>
      its.retTy shouldBe (our ty "@i32")
      its paramTy 0 shouldBe (our ty "@i32")
      its paramTy 1 shouldBe (our ty "@iii8")
Kunshan Wang's avatar
Kunshan Wang committed
111
112
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
113
114
115
    our ty "@f0" shouldBeA[TypeFunc] { _.sig shouldBe (our sig "@sig0") }
    our ty "@f1" shouldBeA[TypeFunc] { _.sig shouldBe (our sig "@sig1") }
    
Kunshan Wang's avatar
Kunshan Wang committed
116
117
118
    our ty "@th" shouldBeA[TypeThread] thatsIt
    our ty "@st" shouldBeA[TypeStack] thatsIt
    our ty "@tr64" shouldBeA[TypeTagRef64] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
119
120
121
122
123
124
125
126
127
128
129
130
131
    
    our ty "@4xfloat" shouldBeA[TypeVector] { its =>
      its.elemTy shouldBe (our ty "@float")
      its.len shouldEqual 4
    }
    our ty "@4xi32" shouldBeA[TypeVector] { its =>
      its.elemTy shouldBe (our ty "@i32")
      its.len shouldEqual 4
    }
    our ty "@2xdouble" shouldBeA[TypeVector] { its =>
      its.elemTy shouldBe (our ty "@double")
      its.len shouldEqual 2
    }
Kunshan Wang's avatar
Kunshan Wang committed
132
  }
Kunshan Wang's avatar
Kunshan Wang committed
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
  
  def validateConstants(bundle: Bundle) {
    val our = bundle

    our const "@ci8" shouldBeAConstIntOf (8, 127)
    our const "@ci16" shouldBeAConstIntOf (16, 32767)
    our const "@ci32" shouldBeAConstIntOf (32, 2147483647)
    our const "@ci64" shouldBeAConstIntOf (64, 9223372036854775807L)
    
    our const "@ci64neg" shouldBeAConstIntOf (64, BigInt(-42L) & 0xffffffffffffffffL)
    
    our const "@cio64" shouldBeAConstIntOf (64, BigInt("777", 8))
    
    our const "@cix64" shouldBeAConstIntOf (64, BigInt("123456789abcdef0", 16))
    our const "@cixovf" shouldBeAConstIntOf (64, BigInt("ffffffffffffffff", 16))
    our const "@cixovf2" shouldBeAConstIntOf (64, BigInt("8000000000000000", 16))
    
    our const "@cf" shouldBeAConstFloatOf 3.14F
    our const "@cfnan" shouldBeAConstFloatOf nan
    our const "@cfninf" shouldBeAConstFloatOf Float.NegativeInfinity 
    our const "@cfpinf" shouldBeAConstFloatOf Float.PositiveInfinity 
    our const "@cfbits" shouldBeAConstFloatOf exactly(bitsf(0x12345678))
  
    our const "@cd" shouldBeAConstDoubleOf 6.28D
    our const "@cdnan" shouldBeAConstDoubleOf nan
    our const "@cdninf" shouldBeAConstDoubleOf Double.NegativeInfinity 
    our const "@cdpinf" shouldBeAConstDoubleOf Double.PositiveInfinity 
    our const "@cdbits" shouldBeAConstDoubleOf exactly(bitsd(0xfedcba9876543210L))
 
    our const "@cs1" shouldBeA[ConstStruct] { its=>
Kunshan Wang's avatar
Kunshan Wang committed
163
164
165
      its.constTy shouldBe (our ty "@s1")
      its fields 0 shouldBe (our const "@ci64")
      its fields 1 shouldBe (our const "@cd")
Kunshan Wang's avatar
Kunshan Wang committed
166
167
168
    }
    
    our const "@cs2" shouldBeA[ConstStruct] { its=>
Kunshan Wang's avatar
Kunshan Wang committed
169
170
171
      its.constTy shouldBe (our ty "@s2")
      its fields 0 shouldBe (our const "@cf")
      its fields 1 shouldBe (our const "@ci64")
Kunshan Wang's avatar
Kunshan Wang committed
172
173
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
    our const "@cs3" shouldBeA[ConstStruct] { its=>
      its.constTy shouldBe (our ty "@s3")
      its fields 0 shouldBe (our const "@cd")
      its fields 1 shouldBe (our const "@cs2")
      its fields 2 shouldBe (our const "@ci32")
    }
      
    our const "@cr" shouldBeA[ConstNull] { _.constTy shouldBe (our ty "@rv") }
    our const "@cir" shouldBeA[ConstNull] { _.constTy shouldBe (our ty "@irv") }
    our const "@cfu" shouldBeA[ConstNull] { _.constTy shouldBe (our ty "@func0") }
    our const "@cth" shouldBeA[ConstNull] { _.constTy shouldBe (our ty "@thread") }
    our const "@cst" shouldBeA[ConstNull] { _.constTy shouldBe (our ty "@stack") }

    our const "@cv4f" shouldBeA[ConstVector] { its =>
      its.constTy shouldBe (our ty "@4xfloat")
      its elems 0 shouldBe (our const "@F_1")
      its elems 1 shouldBe (our const "@F_2")
      its elems 2 shouldBe (our const "@F_3")
      its elems 3 shouldBe (our const "@F_4")
Kunshan Wang's avatar
Kunshan Wang committed
193
194
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
195
196
197
198
199
200
201
202
203
204
205
206
207
    our const "@cv4i" shouldBeA[ConstVector] { its =>
      its.constTy shouldBe (our ty "@4xi32")
      its elems 0 shouldBe (our const "@I32_1")
      its elems 1 shouldBe (our const "@I32_2")
      its elems 2 shouldBe (our const "@I32_3")
      its elems 3 shouldBe (our const "@I32_4")
    }
 
    our const "@cv4d" shouldBeA[ConstVector] { its =>
      its.constTy shouldBe (our ty "@2xdouble")
      its elems 0 shouldBe (our const "@D_1")
      its elems 1 shouldBe (our const "@D_2")
    }
Kunshan Wang's avatar
Kunshan Wang committed
208

Kunshan Wang's avatar
Kunshan Wang committed
209
210
211
212
213
214
215
216
217
    our globalCell "@gi64" shouldBeA[GlobalCell] { _.cellTy shouldBe (our ty "@i64") }

    our func "@fdummy" shouldBeA[Function] { _.sig shouldBe (our sig "@sig0") }
    
    our const "@sgf" shouldBeA[ConstStruct] { its =>
      its.constTy shouldBe (our ty "@sgf_t")
      its fields 0 shouldBe (our globalValue "@gi64")
      its fields 1 shouldBe (our globalValue "@fdummy")
    }
Kunshan Wang's avatar
Kunshan Wang committed
218
219
220
221
222
223
224
225
226
    
    // Testing namespaces
    var ci8 = our const "@ci8"
    our globalValue "@ci8" shouldBe ci8
    our value "@ci8" shouldBe ci8
    
    var gi64 = our globalCell "@gi64"
    our globalValue "@gi64" shouldBe gi64
    our value "@gi64" shouldBe gi64
Kunshan Wang's avatar
Kunshan Wang committed
227
  }
Kunshan Wang's avatar
Kunshan Wang committed
228
  
Kunshan Wang's avatar
Kunshan Wang committed
229
230
  def validateFunctions(bundle: Bundle) {
    val our = bundle
Kunshan Wang's avatar
Kunshan Wang committed
231
232
    
    our sig "@foo" shouldBeA[FuncSig] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
233
      its.retTy shouldBe (our ty "@void")
Kunshan Wang's avatar
Kunshan Wang committed
234
235
      its.paramTy shouldBe empty
    }
Kunshan Wang's avatar
Kunshan Wang committed
236

Kunshan Wang's avatar
Kunshan Wang committed
237
    our sig "@bar" shouldBeA[FuncSig] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
238
239
240
      its.retTy shouldBe (our ty "@i64")
      its paramTy 0 shouldBe (our ty "@i32")
      its paramTy 1 shouldBe (our ty "@i16")
Kunshan Wang's avatar
Kunshan Wang committed
241
242
243
    }
    
    our sig "@baz" shouldBeA[FuncSig] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
244
245
246
      its.retTy shouldBe (our ty "@i32")
      its paramTy 0 shouldBe (our ty "@i32")
      its paramTy 1 shouldBe (our ty "@iii8")
Kunshan Wang's avatar
Kunshan Wang committed
247
248
249
    }
    
    our sig "@sig_fs" shouldBeA[FuncSig] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
250
251
      its.retTy shouldBe (our ty "@void")
      its paramTy 0 shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
252
253
254
255
    }
    
    our ty "@sig_t" shouldBeA[TypeFunc] { _.sig shouldBe (our sig "@sig_fs") }

Kunshan Wang's avatar
Kunshan Wang committed
256
257
258
259
260
261
    our sig "@signal_sig" shouldBeA[FuncSig] { its =>
      its.retTy shouldBe (our ty "@sig_t")
      its paramTy 0 shouldBe (our ty "@i32")
      its paramTy 1 shouldBe (our ty "@sig_t")
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
262
    our func "@signal" shouldBeA[Function] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
263
264
      its.sig shouldBe (our sig "@signal_sig")
      its.versions shouldBe Nil
Kunshan Wang's avatar
Kunshan Wang committed
265
266
267
    }
    
    our const "@zero" shouldBeA[ConstInt] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
268
      its.constTy shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
269
270
271
      its.num shouldBe 0
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
272
    our func "@main" shouldBeA[Function] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
273
      its.sig shouldBe (our sig "@baz")
Kunshan Wang's avatar
Kunshan Wang committed
274
      its.versions.head shouldBe (our funcVer "@main_v1")
Kunshan Wang's avatar
Kunshan Wang committed
275
276
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
277
278
279
280
281
282
283
284
285
286
287
288
289
    our funcVer "@main_v1" shouldBeA[FuncVer] { its =>
      val theFuncVer = its
      its.sig shouldBe (our sig "@baz")
      its params 0 shouldBeA[Parameter] { whose =>
        whose.funcVer shouldEqual theFuncVer
        whose.name.get shouldEqual (globalize("%argc", its.name.get))
        whose.index shouldEqual 0
      }
      its params 1 shouldBeA[Parameter] { whose =>
        whose.funcVer shouldEqual theFuncVer
        whose.name.get shouldEqual (globalize("%argv", its.name.get))
        whose.index shouldEqual 1
      }
Kunshan Wang's avatar
Kunshan Wang committed
290
    }
Kunshan Wang's avatar
Kunshan Wang committed
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    
    // Testing namespaces
    val main = our func "@main"
    our globalValue "@main" shouldBe main
    our value "@main" shouldBe main
    
    val mainV1 = our funcVer "@main_v1"
    
    val argcGN = "@main_v1.argc"
    val argc = mainV1.localVarNs(argcGN)
    our value argcGN shouldBe argc
    
    val addGN = "@main_v1.add"
    val add = mainV1.localVarNs(addGN)
    our value addGN shouldBe add 
Kunshan Wang's avatar
Kunshan Wang committed
306
  }
Kunshan Wang's avatar
Kunshan Wang committed
307
308
309
310

  def in(func: Function)(f: (Function, FuncVer) => Unit) {
    val ver = func.versions.head
    f(func, ver)
Kunshan Wang's avatar
Kunshan Wang committed
311
312
  }
  
Kunshan Wang's avatar
Kunshan Wang committed
313
314
  def validateInstructions(bundle: Bundle) {
    val our = bundle
Kunshan Wang's avatar
Kunshan Wang committed
315
    
Kunshan Wang's avatar
Kunshan Wang committed
316
317
    in (our func "@intBinOpTest") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
      
      my inst "%add"  shouldBeA[InstBinOp] { _.op shouldBe BinOptr.ADD }
      my inst "%sub"  shouldBeA[InstBinOp] { _.op shouldBe BinOptr.SUB }
      my inst "%mul"  shouldBeA[InstBinOp] { _.op shouldBe BinOptr.MUL }
      my inst "%udiv" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.UDIV}
      my inst "%sdiv" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.SDIV}
      my inst "%urem" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.UREM}
      my inst "%srem" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.SREM}
      my inst "%shl"  shouldBeA[InstBinOp] { _.op shouldBe BinOptr.SHL }
      my inst "%lshr" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.LSHR}
      my inst "%ashr" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.ASHR}
      my inst "%and"  shouldBeA[InstBinOp] { _.op shouldBe BinOptr.AND }
      my inst "%or"   shouldBeA[InstBinOp] { _.op shouldBe BinOptr.OR  }
      my inst "%xor"  shouldBeA[InstBinOp] { _.op shouldBe BinOptr.XOR }
      
Kunshan Wang's avatar
Kunshan Wang committed
333
334
      for (i <- ver.localVarNs.all; if i.isInstanceOf[InstBinOp]) {
        i.asInstanceOf[InstBinOp].opndTy shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
335
336
337
338
        i.asInstanceOf[InstBinOp].op1 shouldBe (my param "%p0")
        i.asInstanceOf[InstBinOp].op2 shouldBe (my param "%p1")
      }
    }   
Kunshan Wang's avatar
Kunshan Wang committed
339
340
341

    in (our func "@fpBinOpTest") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
342
343
344
345
346
347
348
      
      my inst "%fadd" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.FADD }
      my inst "%fsub" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.FSUB }
      my inst "%fmul" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.FMUL }
      my inst "%fdiv" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.FDIV }
      my inst "%frem" shouldBeA[InstBinOp] { _.op shouldBe BinOptr.FREM }
      
Kunshan Wang's avatar
Kunshan Wang committed
349
350
      for (i <- ver.localVarNs.all; if i.isInstanceOf[InstBinOp]) {
        i.asInstanceOf[InstBinOp].opndTy shouldBe (our ty "@double")
Kunshan Wang's avatar
Kunshan Wang committed
351
352
353
354
        i.asInstanceOf[InstBinOp].op1 shouldBe (my param "%p0")
        i.asInstanceOf[InstBinOp].op2 shouldBe (my param "%p1")
      }
    }   
Kunshan Wang's avatar
Kunshan Wang committed
355
356
357

    in (our func "@intCmpTest") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
358
359
360
361
362
363
364
365
366
367
368
369
      
      my inst "%eq"  shouldBeA[InstCmp] { _.op shouldBe CmpOptr.EQ  }
      my inst "%ne"  shouldBeA[InstCmp] { _.op shouldBe CmpOptr.NE  }
      my inst "%ult" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.ULT }
      my inst "%ule" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.ULE }
      my inst "%ugt" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.UGT }
      my inst "%uge" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.UGE }
      my inst "%slt" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.SLT }
      my inst "%sle" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.SLE }
      my inst "%sgt" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.SGT }
      my inst "%sge" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.SGE }
      
Kunshan Wang's avatar
Kunshan Wang committed
370
371
      for (i <- ver.localVarNs.all; if i.isInstanceOf[InstCmp]) {
        i.asInstanceOf[InstCmp].opndTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
372
373
374
375
376
        i.asInstanceOf[InstCmp].op1 shouldBe (my param "%p0")
        i.asInstanceOf[InstCmp].op2 shouldBe (my param "%p1")
      }
    }   
    
Kunshan Wang's avatar
Kunshan Wang committed
377
378
    in (our func "@fpCmpTest") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
      
      my inst "%ftrue"  shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FTRUE }
      my inst "%ffalse" shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FFALSE }
      my inst "%ford"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FORD }
      my inst "%foeq"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FOEQ }
      my inst "%fone"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FONE }
      my inst "%folt"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FOLT }
      my inst "%fole"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FOLE }
      my inst "%fogt"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FOGT }
      my inst "%foge"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FOGE }
      my inst "%funo"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FUNO }
      my inst "%fueq"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FUEQ }
      my inst "%fune"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FUNE }
      my inst "%fult"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FULT }
      my inst "%fule"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FULE }
      my inst "%fugt"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FUGT }
      my inst "%fuge"   shouldBeA[InstCmp] { _.op shouldBe CmpOptr.FUGE }
      
Kunshan Wang's avatar
Kunshan Wang committed
397
398
      for (i <- ver.localVarNs.all; if i.isInstanceOf[InstCmp]) {
        i.asInstanceOf[InstCmp].opndTy shouldBe (our ty "@float")
Kunshan Wang's avatar
Kunshan Wang committed
399
400
401
402
        i.asInstanceOf[InstCmp].op1 shouldBe (my param "%p0")
        i.asInstanceOf[InstCmp].op2 shouldBe (my param "%p1")
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
403
404
405

    in (our func "@convTest") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
406
407
408
      
      my inst "%trunc" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.TRUNC
Kunshan Wang's avatar
Kunshan Wang committed
409
410
        its.fromTy shouldBe (our ty "@i64")
        its.toTy   shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
411
412
413
414
        its.opnd   shouldBe (my param "%p1")
      }
      my inst "%zext" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.ZEXT 
Kunshan Wang's avatar
Kunshan Wang committed
415
416
        its.fromTy shouldBe (our ty "@i32")
        its.toTy   shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
417
        its.opnd   shouldBe (my param "%p0")
Kunshan Wang's avatar
Kunshan Wang committed
418

Kunshan Wang's avatar
Kunshan Wang committed
419
420
421
      }
      my inst "%sext" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.SEXT
Kunshan Wang's avatar
Kunshan Wang committed
422
423
        its.fromTy shouldBe (our ty "@i32")
        its.toTy   shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
424
425
426
427
        its.opnd   shouldBe (my param "%p0")
      }
      my inst "%fptrunc" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FPTRUNC
Kunshan Wang's avatar
Kunshan Wang committed
428
429
        its.fromTy shouldBe (our ty "@double")
        its.toTy   shouldBe (our ty "@float")
Kunshan Wang's avatar
Kunshan Wang committed
430
431
432
433
        its.opnd   shouldBe (my param "%p3")
      }
      my inst "%fpext" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FPEXT 
Kunshan Wang's avatar
Kunshan Wang committed
434
435
        its.fromTy shouldBe (our ty "@float")
        its.toTy   shouldBe (our ty "@double")
Kunshan Wang's avatar
Kunshan Wang committed
436
437
438
439
        its.opnd   shouldBe (my param "%p2")
      }
      my inst "%fptoui" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FPTOUI
Kunshan Wang's avatar
Kunshan Wang committed
440
441
        its.fromTy shouldBe (our ty "@double")
        its.toTy   shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
442
443
444
445
        its.opnd   shouldBe (my param "%p3")
      }
      my inst "%fptosi" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FPTOSI
Kunshan Wang's avatar
Kunshan Wang committed
446
447
        its.fromTy shouldBe (our ty "@double")
        its.toTy   shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
448
449
450
451
        its.opnd   shouldBe (my param "%p3")
      }
      my inst "%uitofp" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.UITOFP
Kunshan Wang's avatar
Kunshan Wang committed
452
453
        its.fromTy shouldBe (our ty "@i64")
        its.toTy   shouldBe (our ty "@double")
Kunshan Wang's avatar
Kunshan Wang committed
454
455
456
457
        its.opnd   shouldBe (my param "%p1")
      }
      my inst "%sitofp" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.SITOFP 
Kunshan Wang's avatar
Kunshan Wang committed
458
459
        its.fromTy shouldBe (our ty "@i64")
        its.toTy   shouldBe (our ty "@double")
Kunshan Wang's avatar
Kunshan Wang committed
460
461
462
463
        its.opnd   shouldBe (my param "%p1")
      }
      my inst "%bitcast0" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.BITCAST 
Kunshan Wang's avatar
Kunshan Wang committed
464
465
        its.fromTy shouldBe (our ty "@i32")
        its.toTy   shouldBe (our ty "@float")
Kunshan Wang's avatar
Kunshan Wang committed
466
467
468
469
        its.opnd   shouldBe (my param "%p0")
      }
      my inst "%bitcast1" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.BITCAST 
Kunshan Wang's avatar
Kunshan Wang committed
470
471
        its.fromTy shouldBe (our ty "@i64")
        its.toTy   shouldBe (our ty "@double")
Kunshan Wang's avatar
Kunshan Wang committed
472
473
474
475
        its.opnd   shouldBe (my param "%p1")
      }
      my inst "%bitcast2" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.BITCAST 
Kunshan Wang's avatar
Kunshan Wang committed
476
477
        its.fromTy shouldBe (our ty "@float")
        its.toTy   shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
478
479
480
481
        its.opnd   shouldBe (my param "%p2")
      }
      my inst "%bitcast3" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.BITCAST 
Kunshan Wang's avatar
Kunshan Wang committed
482
483
        its.fromTy shouldBe (our ty "@double")
        its.toTy   shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
484
485
486
        its.opnd   shouldBe (my param "%p3")
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
487

Kunshan Wang's avatar
Kunshan Wang committed
488
489
    in (our func "@refCastTest") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
490
491
492
      
      my inst "%refcast" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.REFCAST
Kunshan Wang's avatar
Kunshan Wang committed
493
494
        its.fromTy shouldBe (our ty "@rv")
        its.toTy   shouldBe (our ty "@ri32")
Kunshan Wang's avatar
Kunshan Wang committed
495
496
497
        its.opnd   shouldBe (my param "%p0")
      }
      my inst "%irefcast" shouldBeA[InstConv] { its => 
Kunshan Wang's avatar
Kunshan Wang committed
498
499
500
        its.op     shouldBe ConvOptr.REFCAST
        its.fromTy shouldBe (our ty "@irv")
        its.toTy   shouldBe (our ty "@ii64")
Kunshan Wang's avatar
Kunshan Wang committed
501
502
503
        its.opnd   shouldBe (my param "%p1")
      }
      my inst "%funccast" shouldBeA[InstConv] { its => 
Kunshan Wang's avatar
Kunshan Wang committed
504
505
506
        its.op     shouldBe ConvOptr.REFCAST
        its.fromTy shouldBe (our ty "@npnr_func")
        its.toTy   shouldBe (our ty "@iii_func")
Kunshan Wang's avatar
Kunshan Wang committed
507
508
509
        its.opnd   shouldBe (my param "%p2")
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
510
511
512

    in (our func "@ctrlFlow") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
513
514
515
516
517
518
519
520
521
522
523
524
525
526
      
      my inst "%br1" shouldBeA[InstBranch] { _.dest shouldBe (my bb "%head") }
      my inst "%br3" shouldBeA[InstBranch] { _.dest shouldBe (my bb "%next") }
      my inst "%br4" shouldBeA[InstBranch] { _.dest shouldBe (my bb "%next") }
      my inst "%br5" shouldBeA[InstBranch] { _.dest shouldBe (my bb "%next") }
      my inst "%br6" shouldBeA[InstBranch] { _.dest shouldBe (my bb "%head") }
      
      my inst "%br2" shouldBeA[InstBranch2] { its =>
        its.cond shouldBe (my inst "%zero")
        its.ifTrue shouldBe (my bb "%body")
        its.ifFalse shouldBe (my bb "%exit")
      }
      
      my inst "%switch" shouldBeA[InstSwitch] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
527
        its.opndTy shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
528
529
        its.opnd shouldBe (my inst "%phi")
        its.defDest shouldBe (my bb "%other")
Kunshan Wang's avatar
Kunshan Wang committed
530
531
        its cases 0 shouldBe ((our value "@I32_1"), (my bb "%one"))  
        its cases 1 shouldBe ((our value "@I32_2"), (my bb "%two"))  
Kunshan Wang's avatar
Kunshan Wang committed
532
533
534
      }
      
      my inst "%phi" shouldBeA[InstPhi] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
535
536
537
        its.opndTy shouldBe (our ty "@i32")
        its cases 0 shouldBe ((my bb "%entry"), (our value "@I32_0"))
        its cases 1 shouldBe ((my bb "%next"), (my value "%i2"))
Kunshan Wang's avatar
Kunshan Wang committed
538
      }
Kunshan Wang's avatar
Kunshan Wang committed
539
540
541
542
    }
    
    in (our func "@callee2") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
543
      
Kunshan Wang's avatar
Kunshan Wang committed
544
545
546
547
548
549
550
551
552
553
554
555
      my inst "%ret" shouldBeA[InstRet] { its =>
        its.retTy shouldBe (our ty "@i64")
        its.retVal shouldBe (my inst "%rv")
      }
    }     
 
    in (our func "@callee3") { (func, ver) =>
      val my = ver
      
      my inst "%throw" shouldBeA[InstThrow] { its =>
        its.excVal shouldBe (my inst "%exc")
      }
Kunshan Wang's avatar
Kunshan Wang committed
556
    }
Kunshan Wang's avatar
Kunshan Wang committed
557
558
559

    in (our func "@caller1") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
560
561
      
      my inst "%v1" shouldBeA[InstCall] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
562
563
564
565
566
        its.sig shouldBe (our sig "@npnr_sig")
        its.callee shouldBe (our value "@callee1")
        its.argList shouldBe empty
        its.excClause shouldBe None
        its.keepAlives shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
567
568
569
      }
      
      my inst "%v2" shouldBeA[InstCall] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
570
571
572
573
574
        its.sig shouldBe (our sig "@iii_sig")
        its.callee shouldBe (our value "@callee2")
        its.argList shouldEqual Seq("@I64_1", "@I64_2").map(our.value)
        its.excClause shouldBe None
        its.keepAlives shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
575
      }
Kunshan Wang's avatar
Kunshan Wang committed
576
577
578
579
580
581
582
583

      my inst "%v3" shouldBeA[InstCall] { its =>
        its.sig shouldBe (our sig "@iii_sig")
        its.callee shouldBe (our value "@callee3")
        its.argList shouldEqual Seq("@I64_1", "@I64_2").map(our.value)
        its.excClause shouldEqual Some(ExcClause((my bb "%cont"), (my bb "%catch")))
        its.keepAlives shouldBe empty
      }     
Kunshan Wang's avatar
Kunshan Wang committed
584
585
      
      my inst "%v4" shouldBeA[InstCall] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
586
        its.sig shouldBe (our sig "@npnr_sig")
Kunshan Wang's avatar
Kunshan Wang committed
587
        its.callee shouldBe (our globalValue "@callee1")
Kunshan Wang's avatar
Kunshan Wang committed
588
589
590
        its.argList shouldBe empty
        its.excClause shouldBe None
        its.keepAlives shouldBe Seq("%v2", "%v3").map(my.value)
Kunshan Wang's avatar
Kunshan Wang committed
591
592
      }

Kunshan Wang's avatar
Kunshan Wang committed
593
594
      my inst "%v5" shouldBeA[InstCall] { its =>
        its.sig shouldBe (our sig "@iii_sig")
Kunshan Wang's avatar
Kunshan Wang committed
595
        its.callee shouldBe (our globalValue "@callee3")
Kunshan Wang's avatar
Kunshan Wang committed
596
597
598
        its.argList shouldBe Seq("%v3", "%v3").map(my.value)
        its.excClause shouldEqual Some(ExcClause((my bb "%cont2"), (my bb "%catch")))
        its.keepAlives shouldEqual Seq(my value "%v2")
Kunshan Wang's avatar
Kunshan Wang committed
599
600
      }  
      
Kunshan Wang's avatar
Kunshan Wang committed
601
602
      my inst "%retv" shouldBeA[InstRetVoid] thatsIt
      my inst "%exc" shouldBeA[InstLandingPad] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
603
    }
Kunshan Wang's avatar
Kunshan Wang committed
604
605
606

    in (our func "@caller2") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
607
608
      
      my inst "%tc" shouldBeA[InstTailCall] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
609
        its.sig shouldBe (our sig "@iii_sig")
Kunshan Wang's avatar
Kunshan Wang committed
610
        its.callee shouldBe (our globalValue "@callee2")
Kunshan Wang's avatar
Kunshan Wang committed
611
        its.argList shouldEqual Seq("%p0", "%p1").map(my.inst)
Kunshan Wang's avatar
Kunshan Wang committed
612
613
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
614
615
616

    in (our func "@aggregate") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
617
618
619
620
      
      my inst "%e0" shouldBeA[InstExtractValue] { its =>
        its.strTy shouldBe (our ty "@sid")
        its.index shouldBe 0
Kunshan Wang's avatar
Kunshan Wang committed
621
        its.opnd shouldBe (our value "@sid1")
Kunshan Wang's avatar
Kunshan Wang committed
622
623
624
625
626
      }
      
      my inst "%e1" shouldBeA[InstExtractValue] { its =>
        its.strTy shouldBe (our ty "@sid")
        its.index shouldBe 1
Kunshan Wang's avatar
Kunshan Wang committed
627
        its.opnd shouldBe (our value "@sid1")
Kunshan Wang's avatar
Kunshan Wang committed
628
629
630
631
632
      }
      
      my inst "%i0" shouldBeA[InstInsertValue] { its =>
        its.strTy shouldBe (our ty "@sid")
        its.index shouldBe 0
Kunshan Wang's avatar
Kunshan Wang committed
633
634
        its.opnd shouldBe (our value "@sid1")
        its.newVal shouldBe (our value "@I64_0")
Kunshan Wang's avatar
Kunshan Wang committed
635
636
637
638
639
      }
      
      my inst "%i1" shouldBeA[InstInsertValue] { its =>
        its.strTy shouldBe (our ty "@sid")
        its.index shouldBe 1
Kunshan Wang's avatar
Kunshan Wang committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
        its.opnd shouldBe (our value "@sid1")
        its.newVal shouldBe (our value "@D_0")
      }
      
      my inst "%ee0" shouldBeA[InstExtractElement] { its =>
        its.vecTy shouldBe (our ty "@4xfloat")
        its.indTy shouldBe (our ty "@i32")
        its.opnd shouldBe (our value "@v1")
        its.index shouldBe (our value "@I32_0")
      }
      
      my inst "%ie0" shouldBeA[InstInsertElement] { its =>
        its.vecTy shouldBe (our ty "@4xfloat")
        its.indTy shouldBe (our ty "@i32")
        its.opnd shouldBe (our value "@v1")
        its.index shouldBe (our value "@I32_1")
        its.newVal shouldBe (our value "@F_1")
      }
      
      my inst "%sv0" shouldBeA[InstShuffleVector] { its =>
        its.vecTy shouldBe (our ty "@4xfloat")
        its.maskTy shouldBe (our ty "@4xi32")
        its.vec1 shouldBe (our value "@v1")
        its.vec2 shouldBe (our value "@v2")
        its.mask shouldBe (our value "@vshf")
Kunshan Wang's avatar
Kunshan Wang committed
665
666
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
667
668
669

    in (our func "@memops") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
670
671
      
      my inst "%new" shouldBeA[InstNew] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
672
673
        its.allocTy shouldBe (our ty "@i64")
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
674
675
676
677
      }
      
      my inst "%newhybrid" shouldBeA[InstNewHybrid] { its =>
        its.allocTy shouldBe (our ty "@hic")
Kunshan Wang's avatar
Kunshan Wang committed
678
        its.lenTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
679
        its.length shouldBe (my param "%p0")
Kunshan Wang's avatar
Kunshan Wang committed
680
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
681
682
683
      }
      
      my inst "%alloca" shouldBeA[InstAlloca] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
684
685
        its.allocTy shouldBe (our ty "@i64")
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
686
687
688
689
      }
      
      my inst "%allocahybrid" shouldBeA[InstAllocaHybrid] { its =>
        its.allocTy shouldBe (our ty "@hic")
Kunshan Wang's avatar
Kunshan Wang committed
690
691
692
693
694
695
696
697
698
699
700
701
702
        its.lenTy shouldBe (our ty "@i64")
        its.length shouldBe (my param "%p0")
        its.excClause shouldBe None
      }
     
      my inst "%new_s" shouldBeA[InstNew] { its =>
        its.allocTy shouldBe (our ty "@i64")
        its.excClause shouldBe Some(ExcClause((my bb "%bb2"), (my bb "%handler")))
      }
      
      my inst "%newhybrid_s" shouldBeA[InstNewHybrid] { its =>
        its.allocTy shouldBe (our ty "@hic")
        its.lenTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
703
        its.length shouldBe (my param "%p0")
Kunshan Wang's avatar
Kunshan Wang committed
704
705
706
707
708
709
710
711
712
713
714
715
716
        its.excClause shouldBe Some(ExcClause((my bb "%bb3"), (my bb "%handler")))
      }
      
      my inst "%alloca_s" shouldBeA[InstAlloca] { its =>
        its.allocTy shouldBe (our ty "@i64")
        its.excClause shouldBe Some(ExcClause((my bb "%bb4"), (my bb "%handler")))
      }
      
      my inst "%allocahybrid_s" shouldBeA[InstAllocaHybrid] { its =>
        its.allocTy shouldBe (our ty "@hic")
        its.lenTy shouldBe (our ty "@i64")
        its.length shouldBe (my param "%p0")
        its.excClause shouldBe Some(ExcClause((my bb "%bb5"), (my bb "%handler")))
Kunshan Wang's avatar
Kunshan Wang committed
717
718
719
720
      }

      my inst "%new2" shouldBeA[InstNew] { its =>
        its.allocTy shouldBe (our ty "@sid")
Kunshan Wang's avatar
Kunshan Wang committed
721
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
722
723
724
725
      }
      
      my inst "%alloca2" shouldBeA[InstAlloca] { its =>
        its.allocTy shouldBe (our ty "@al")
Kunshan Wang's avatar
Kunshan Wang committed
726
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
727
728
729
730
731
732
      }
      
      my inst "%getiref" shouldBeA[InstGetIRef] { its =>
        its.referentTy shouldBe (our ty "@sid")
        its.opnd shouldBe (my inst "%new2")
      }
Kunshan Wang's avatar
Kunshan Wang committed
733
734
735
736
737
738
739
740
741
      
      my inst "%getfieldiref" shouldBeA[InstGetFieldIRef] { its =>
        its.referentTy shouldBe (our ty "@sid")
        its.index shouldBe 0
        its.opnd shouldBe (my inst "%getiref")
      }
      
      my inst "%getelemiref" shouldBeA[InstGetElemIRef] { its =>
        its.referentTy shouldBe (our ty "@al")
Kunshan Wang's avatar
Kunshan Wang committed
742
        its.indTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
743
744
745
746
747
        its.opnd shouldBe (my inst "%alloca2")
        its.index shouldBe (my param "%p1")
      }
      
      my inst "%shiftiref" shouldBeA[InstShiftIRef] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
748
749
        its.referentTy shouldBe (our ty "@i8")
        its.offTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
        its.opnd shouldBe (my inst "%getvarpartiref")
        its.offset shouldBe (my param "%p1")
      }

      my inst "%getfixedpartiref" shouldBeA[InstGetFixedPartIRef] { its =>
        its.referentTy shouldBe (our ty "@hic")
        its.opnd shouldBe (my inst "%allocahybrid")
      }
      
      my inst "%getvarpartiref" shouldBeA[InstGetVarPartIRef] { its =>
        its.referentTy shouldBe (our ty "@hic")
        its.opnd shouldBe (my inst "%allocahybrid")
      }
      
      my inst "%load" shouldBeA[InstLoad] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
765
766
        its.ord shouldBe MemoryOrder.NOT_ATOMIC
        its.referentTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
767
        its.loc shouldBe (my inst "%alloca")
Kunshan Wang's avatar
Kunshan Wang committed
768
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
769
770
771
      }
      
      my inst "%store" shouldBeA[InstStore] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
772
773
        its.ord shouldBe MemoryOrder.NOT_ATOMIC
        its.referentTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
774
        its.loc shouldBe (my inst "%alloca")
Kunshan Wang's avatar
Kunshan Wang committed
775
776
        its.newVal shouldBe (our const "@I64_42")
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
777
778
779
      }
      
      my inst "%cmpxchg" shouldBeA[InstCmpXchg] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
780
781
782
        its.ordSucc shouldBe MemoryOrder.SEQ_CST
        its.ordFail shouldBe MemoryOrder.SEQ_CST
        its.referentTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
783
        its.loc shouldBe (my inst "%alloca")
Kunshan Wang's avatar
Kunshan Wang committed
784
785
786
        its.expected shouldBe (our const "@I64_42")
        its.desired shouldBe (our const "@I64_0")
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
787
788
789
      }
    
      my inst "%atomicrmw" shouldBeA[InstAtomicRMW] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
790
        its.ord shouldBe MemoryOrder.SEQ_CST
Kunshan Wang's avatar
Kunshan Wang committed
791
        its.op shouldBe AtomicRMWOptr.ADD
Kunshan Wang's avatar
Kunshan Wang committed
792
        its.referentTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
793
        its.loc shouldBe (my inst "%alloca")
Kunshan Wang's avatar
Kunshan Wang committed
794
795
        its.opnd shouldBe (our const "@I64_43")
        its.excClause shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
796
797
      }
   
Kunshan Wang's avatar
Kunshan Wang committed
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
      my inst "%load_s" shouldBeA[InstLoad] { its =>
        its.ord shouldBe MemoryOrder.NOT_ATOMIC
        its.referentTy shouldBe (our ty "@i64")
        its.loc shouldBe (my inst "%alloca")
        its.excClause shouldBe Some(ExcClause((my bb "%bb6"), (my bb "%handler")))
      }
      
      my inst "%store_s" shouldBeA[InstStore] { its =>
        its.ord shouldBe MemoryOrder.NOT_ATOMIC
        its.referentTy shouldBe (our ty "@i64")
        its.loc shouldBe (my inst "%alloca")
        its.newVal shouldBe (our const "@I64_42")
        its.excClause shouldBe Some(ExcClause((my bb "%bb7"), (my bb "%handler")))
      }
      
      my inst "%cmpxchg_s" shouldBeA[InstCmpXchg] { its =>
        its.ordSucc shouldBe MemoryOrder.SEQ_CST
        its.ordFail shouldBe MemoryOrder.SEQ_CST
        its.referentTy shouldBe (our ty "@i64")
        its.loc shouldBe (my inst "%alloca")
        its.expected shouldBe (our const "@I64_42")
        its.desired shouldBe (our const "@I64_0")
        its.excClause shouldBe Some(ExcClause((my bb "%bb8"), (my bb "%handler")))
     }
    
      my inst "%atomicrmw_s" shouldBeA[InstAtomicRMW] { its =>
        its.ord shouldBe MemoryOrder.SEQ_CST
        its.op shouldBe AtomicRMWOptr.ADD
        its.referentTy shouldBe (our ty "@i64")
        its.loc shouldBe (my inst "%alloca")
        its.opnd shouldBe (our const "@I64_43")
        its.excClause shouldBe Some(ExcClause((my bb "%bb9"), (my bb "%handler")))
      }
      
Kunshan Wang's avatar
Kunshan Wang committed
832
      my inst "%fence" shouldBeA[InstFence] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
833
        its.ord shouldBe (MemoryOrder.SEQ_CST)
Kunshan Wang's avatar
Kunshan Wang committed
834
835
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
836
837
838
839
840
841
842
843
844
845
846
847
848
849

    in (our func "@memorder") { (func, ver) =>
      val my = ver
      
      my inst "%l0" shouldBeA[InstLoad] { _.ord shouldBe MemoryOrder.NOT_ATOMIC }
      my inst "%l1" shouldBeA[InstLoad] { _.ord shouldBe MemoryOrder.RELAXED }
      my inst "%l2" shouldBeA[InstLoad] { _.ord shouldBe MemoryOrder.CONSUME }
      my inst "%l3" shouldBeA[InstLoad] { _.ord shouldBe MemoryOrder.ACQUIRE }
      my inst "%s4" shouldBeA[InstStore] { _.ord shouldBe MemoryOrder.RELEASE }
      my inst "%c5" shouldBeA[InstCmpXchg] { its =>
        its.ordSucc shouldBe MemoryOrder.ACQ_REL
        its.ordFail shouldBe MemoryOrder.ACQUIRE
      }
      my inst "%l6" shouldBeA[InstLoad] { _.ord shouldBe MemoryOrder.SEQ_CST }
Kunshan Wang's avatar
Kunshan Wang committed
850
851
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
    in (our func "@atomicrmwops") { (func, ver) =>
      val my = ver
      
      my inst "%old0" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.XCHG }
      my inst "%old1" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.ADD }
      my inst "%old2" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.SUB }
      my inst "%old3" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.AND }
      my inst "%old4" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.NAND }
      my inst "%old5" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.OR }
      my inst "%old6" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.XOR }
      my inst "%old7" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.MAX }
      my inst "%old8" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.MIN }
      my inst "%old9" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.UMAX }
      my inst "%olda" shouldBeA[InstAtomicRMW] { _.op shouldBe AtomicRMWOptr.UMIN }
Kunshan Wang's avatar
Kunshan Wang committed
866
    }
Kunshan Wang's avatar
Kunshan Wang committed
867

Kunshan Wang's avatar
Kunshan Wang committed
868
869
    in (our func "@traps") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
870
871
      
      my inst "%tp" shouldBeA[InstTrap] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
872
        its.retTy shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
873
874
875
876
877
878
879
880
        its.excClause shouldBe None
        its.keepAlives shouldBe Seq(my inst "%a")
      }
       
      my inst "%tp_s" shouldBeA[InstTrap] { its =>
        its.retTy shouldBe (our ty "@i64")
        its.excClause shouldBe Some(ExcClause(my bb "%tp_s_cont", my bb "%tp_s_exc"))
        its.keepAlives shouldBe Seq(my inst "%b")
Kunshan Wang's avatar
Kunshan Wang committed
881
882
      }
      
Kunshan Wang's avatar
Kunshan Wang committed
883
      my inst "%wp" shouldBeA[InstWatchPoint] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
884
        its.wpID shouldBe 1
Kunshan Wang's avatar
Kunshan Wang committed
885
886
887
888
        its.retTy shouldBe (our ty "@float")
        its.dis shouldBe (my bb "%wp_dis_cont")
        its.ena shouldBe (my bb "%wp_ena_cont")
        its.exc shouldBe None
Kunshan Wang's avatar
Kunshan Wang committed
889
890
        its.keepAlives shouldBe Seq(my inst "%a")
      }
Kunshan Wang's avatar
Kunshan Wang committed
891
892
893
894
895
896
897
898
899
      
      my inst "%wp_s" shouldBeA[InstWatchPoint] { its =>
        its.wpID shouldBe 2
        its.retTy shouldBe (our ty "@double")
        its.dis shouldBe (my bb "%wp_s_dis_cont")
        its.ena shouldBe (my bb "%wp_s_ena_cont")
        its.exc shouldBe Some(my bb "%wp_s_exc")
        its.keepAlives shouldBe Seq(my inst "%b")
      }
Kunshan Wang's avatar
Kunshan Wang committed
900
    }
Kunshan Wang's avatar
Kunshan Wang committed
901

Kunshan Wang's avatar
Kunshan Wang committed
902
903
    in (our func "@ccall") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
904
905
906
      
      my inst "%rv" shouldBeA[InstCCall] { its =>
        its.callConv shouldBe CallConv.DEFAULT
Kunshan Wang's avatar
Kunshan Wang committed
907
908
        its.funcTy shouldBe (our ty "@i64")
        its.sig shouldBe (our sig "@ccall_callee_sig")
Kunshan Wang's avatar
Kunshan Wang committed
909
        its.callee shouldBe (my param "%p0")
Kunshan Wang's avatar
Kunshan Wang committed
910
        its.argList shouldBe Seq(our value "@D_1")
Kunshan Wang's avatar
Kunshan Wang committed
911
912
913
      }
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
914
    in (our func "@gen") { (func, ver) =>
Kunshan Wang's avatar
Kunshan Wang committed
915
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
916
      
Kunshan Wang's avatar
Kunshan Wang committed
917
918
919
920
921
922
      my inst "%ss1" shouldBeA[InstSwapStack] { its =>
        its.swappee shouldBe (my value "%main")
        its.curStackAction shouldBe RetWith(our ty "@void")
        its.newStackAction shouldBe PassValue(our ty "@i64", our value "@I64_0")
        its.excClause shouldBe None
        its.keepAlives shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
923
      }
Kunshan Wang's avatar
Kunshan Wang committed
924
925
926
927
928
929
      my inst "%ss2" shouldBeA[InstSwapStack] { its =>
        its.swappee shouldBe (my value "%main")
        its.curStackAction shouldBe KillOld()
        its.newStackAction shouldBe ThrowExc(our value "@NULLREF")
        its.excClause shouldBe None
        its.keepAlives shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
930
931
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
932
933
   
    in (our func "@swapstack") { (func, ver) =>
Kunshan Wang's avatar
Kunshan Wang committed
934
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
935
      
Kunshan Wang's avatar
Kunshan Wang committed
936
937
938
939
940
941
      my inst "%curstack" shouldBeA[InstCommInst] { its =>
        its.inst shouldBe (CommInsts("@uvm.current_stack"))
        its.typeList shouldBe empty
        its.argList shouldBe empty
        its.excClause shouldBe None
        its.keepAlives shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
942
943
      }
      
Kunshan Wang's avatar
Kunshan Wang committed
944
945
946
947
948
      my inst "%coro" shouldBeA[InstNewStack] { its =>
        its.sig shouldBe (our sig "@iii_sig")
        its.callee shouldBe (our value "@callee2")
        its.argList shouldBe Seq(my value "%curstack")
        its.excClause shouldBe Some(ExcClause(my bb "%cont", my bb "%exc"))
Kunshan Wang's avatar
Kunshan Wang committed
949
950
      }
      
Kunshan Wang's avatar
Kunshan Wang committed
951
952
953
954
955
956
      my inst "%ss1" shouldBeA[InstSwapStack] { its =>
        its.swappee shouldBe (my value "%coro")
        its.curStackAction shouldBe RetWith(our ty "@i64")
        its.newStackAction shouldBe PassVoid()
        its.excClause shouldBe None
        its.keepAlives shouldBe Seq(my value "%curstack")
Kunshan Wang's avatar
Kunshan Wang committed
957
      }
Kunshan Wang's avatar
Kunshan Wang committed
958
959
960
961
962
963
      my inst "%ss2" shouldBeA[InstSwapStack] { its =>
        its.swappee shouldBe (my value "%coro")
        its.curStackAction shouldBe RetWith(our ty "@i64")
        its.newStackAction shouldBe PassVoid()
        its.excClause shouldBe Some(ExcClause(my bb "%nor", my bb "%exc"))
        its.keepAlives shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
964
      }
Kunshan Wang's avatar
Kunshan Wang committed
965
966
967
968
    }
    
    in (our func "@comminst") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
969
      
Kunshan Wang's avatar
Kunshan Wang committed
970
971
972
973
974
975
      my inst "%thr" shouldBeA[InstCommInst] { its =>
        its.inst shouldBe CommInsts("@uvm.new_thread")
        its.typeList shouldBe empty
        its.argList shouldBe Seq(my value "%sta")
        its.excClause shouldBe None
        its.keepAlives shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
976
977
      }
      
Kunshan Wang's avatar
Kunshan Wang committed
978
979
980
981
982
983
      my inst "%th_ex" shouldBeA[InstCommInst] { its =>
        its.inst shouldBe CommInsts("@uvm.thread_exit")
        its.typeList shouldBe empty
        its.argList shouldBe empty
        its.excClause shouldBe None
        its.keepAlives shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
984
      }
Kunshan Wang's avatar
Kunshan Wang committed
985

Kunshan Wang's avatar
Kunshan Wang committed
986
    }
Kunshan Wang's avatar
Kunshan Wang committed
987
  }
Kunshan Wang's avatar
Kunshan Wang committed
988

Kunshan Wang's avatar
Kunshan Wang committed
989
990
991
992
  def validateRedef(globalBundle: Bundle, bundle: Bundle) {
    val ourOld = globalBundle
    val ourNew = bundle
    
Kunshan Wang's avatar
Kunshan Wang committed
993
994
    in (ourOld func "@meaning_of_life") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
995
      
Kunshan Wang's avatar
Kunshan Wang committed
996
997
998
999
      my inst "%ret" shouldBeA[InstRet] { its =>
        its.retTy shouldBe (ourOld ty "@i64")
        its.retVal shouldBe (ourOld const "@I64_42")
      }
Kunshan Wang's avatar
Kunshan Wang committed
1000
1001
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
1002
1003
    (ourOld func "@foxsay").versions shouldBe Nil
    (ourOld func "@meaning_of_life").versions shouldBe Seq(ourOld funcVer "@meaning_of_life_v1")
Kunshan Wang's avatar
Kunshan Wang committed
1004
1005
1006
1007
    
    (ourNew func "@meaning_of_life").id shouldEqual (ourOld func "@meaning_of_life").id
    (ourNew func "@foxsay").id shouldEqual (ourOld func "@foxsay").id
    
Kunshan Wang's avatar
Kunshan Wang committed
1008
1009
    in (ourNew func "@meaning_of_life") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
1010
1011
1012
      
      my inst "%ret" shouldBeA[InstRet] { its =>
        its.retTy shouldBe (ourOld ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
1013
        its.retVal shouldBe (ourNew const "@I64_43")
Kunshan Wang's avatar
Kunshan Wang committed
1014
1015
1016
      }
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
1017
1018
    (ourNew func "@foxsay").versions shouldBe Seq(ourNew funcVer "@foxsay_v1")
    (ourNew func "@meaning_of_life").versions shouldBe Seq(ourNew funcVer "@meaning_of_life_v2")
Kunshan Wang's avatar
Kunshan Wang committed
1019
    
Kunshan Wang's avatar
Kunshan Wang committed
1020
1021
    in (ourNew func "@foxsay") { (func, ver) =>
      val my = ver
Kunshan Wang's avatar
Kunshan Wang committed
1022
      
Kunshan Wang's avatar
Kunshan Wang committed
1023
1024
1025
1026
      my inst "%ret" shouldBeA[InstRet] { its =>
        its.retTy shouldBe (ourOld ty "@i64")
        its.retVal shouldBe (ourNew const "@I64_99")
      }
Kunshan Wang's avatar
Kunshan Wang committed
1027
1028
    }
  }
Kunshan Wang's avatar
Kunshan Wang committed
1029
  
Kunshan Wang's avatar
Kunshan Wang committed
1030
1031
1032
1033
  def validateRedefAfterMerge(globalBundle: Bundle, bundle: Bundle) {
    val ourGlobal = globalBundle
    val ourNew = bundle
    
Kunshan Wang's avatar
Kunshan Wang committed
1034
1035
    (ourGlobal func "@foxsay").versions.head shouldBe (ourNew funcVer "@foxsay_v1")
    (ourGlobal func "@meaning_of_life").versions.head shouldBe (ourNew funcVer "@meaning_of_life_v2")
Kunshan Wang's avatar
Kunshan Wang committed
1036
1037
1038
1039
    
    val foxSay = ourGlobal func "@foxsay"
    ourGlobal value "@foxsay" shouldBe foxSay
    ourGlobal globalValue "@foxsay" shouldBe foxSay
Kunshan Wang's avatar
Kunshan Wang committed
1040
  }
Kunshan Wang's avatar
Kunshan Wang committed
1041

Kunshan Wang's avatar
Kunshan Wang committed
1042
}