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 49.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
import org.scalatest._

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

trait TestingBundlesValidators extends Matchers with ExtraMatchers {
  
  implicit class MagicalOur(b: Bundle) {
13
    def anything(s: String) = b.allNs(s)
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)
22
    def expFunc(s: String) = b.expFuncNs(s)
Kunshan Wang's avatar
Kunshan Wang committed
23
  }
Kunshan Wang's avatar
Kunshan Wang committed
24
  
Kunshan Wang's avatar
Kunshan Wang committed
25
  implicit class MagicalThe(c: FuncVer) {
Kunshan Wang's avatar
Kunshan Wang committed
26
27
    def globalName(s: String) = UIRTextReader.globalize(s, c.name.get)
    def bb(s: String) = c.bbNs(UIRTextReader.globalize(s, c.name.get))
Kunshan Wang's avatar
Kunshan Wang committed
28
29
30
31
32
33
34
  }
  
  implicit class MagicalMy(d: BasicBlock) {
    def globalName(s: String) = UIRTextReader.globalize(s, d.name.get)
    def value(s: String) = d.localVarNs(UIRTextReader.globalize(s, d.name.get))
    def param(s: String) = d.localVarNs(UIRTextReader.globalize(s, d.name.get))
    def inst(s: String) = d.localVarNs(UIRTextReader.globalize(s, d.name.get))
Kunshan Wang's avatar
Kunshan Wang committed
35
36
  }

Kunshan Wang's avatar
Kunshan Wang committed
37
  def validateTypes(bundle: GlobalBundle) {
Kunshan Wang's avatar
Kunshan Wang committed
38
39
    val our = bundle
    
Kunshan Wang's avatar
Kunshan Wang committed
40
41
42
43
44
    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
45
    
Kunshan Wang's avatar
Kunshan Wang committed
46
47
    our ty "@float" shouldBeA[TypeFloat] thatsIt
    our ty "@double" shouldBeA[TypeDouble] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
48
    
Kunshan Wang's avatar
Kunshan Wang committed
49
50
51
    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
52
    
Kunshan Wang's avatar
Kunshan Wang committed
53
    our ty "@ri16" shouldBeA[TypeRef] { _.ty shouldBe (our ty "@i16")}
Kunshan Wang's avatar
Kunshan Wang committed
54
55

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

    our ty "@foo" shouldBeA[TypeStruct] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
76
77
      its fieldTys 0 shouldBe (our ty "@double")
      its fieldTys 1 shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
78
79
    }

Kunshan Wang's avatar
Kunshan Wang committed
80
    our ty "@a0" shouldBeA[TypeArray] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
81
      its.elemTy shouldBe (our ty "@i8")
Kunshan Wang's avatar
Kunshan Wang committed
82
83
84
      its.len shouldEqual 100
    }
    our ty "@a1" shouldBeA[TypeArray] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
85
      its.elemTy shouldBe (our ty "@foo")
Kunshan Wang's avatar
Kunshan Wang committed
86
87
88
89
90
91
92
93
      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
94
95
      its.fixedTy shouldBe (our ty "@void")
      its.varTy shouldBe (our ty "@i8")
Kunshan Wang's avatar
Kunshan Wang committed
96
97
    }
    our ty "@h1" shouldBeA[TypeHybrid] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
98
99
      its.fixedTy shouldBe (our ty "@foo")
      its.varTy shouldBe (our ty "@i64")
Kunshan Wang's avatar
Kunshan Wang committed
100
101
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
102
    our ty "@void" shouldBeA[TypeVoid] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
103
    
Kunshan Wang's avatar
Kunshan Wang committed
104
105
106
    our sig "@sig0" shouldBeA[FuncSig] { its =>
      its.retTy shouldBe (our ty "@void")
      its.paramTy shouldBe empty
Kunshan Wang's avatar
Kunshan Wang committed
107
    }
Kunshan Wang's avatar
Kunshan Wang committed
108
109
110
111
112
113
114
115
    
    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
116
117
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
118
119
    our ty "@f0" shouldBeA[TypeFuncRef] { _.sig shouldBe (our sig "@sig0") }
    our ty "@f1" shouldBeA[TypeFuncRef] { _.sig shouldBe (our sig "@sig1") }
Kunshan Wang's avatar
Kunshan Wang committed
120
    
Kunshan Wang's avatar
Kunshan Wang committed
121
122
    our ty "@th" shouldBeA[TypeThreadRef] thatsIt
    our ty "@st" shouldBeA[TypeStackRef] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
123
    our ty "@tr64" shouldBeA[TypeTagRef64] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
124
125
126
127
128
129
130
131
132
133
134
135
136
    
    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
    }
137
    
Kunshan Wang's avatar
Kunshan Wang committed
138
139
140
141
    our ty "@i32_p" shouldBeA[TypeUPtr] { its => its.ty shouldBe (our ty "@i32") }
    our ty "@i64_p" shouldBeA[TypeUPtr] { its => its.ty shouldBe (our ty "@i64") }
    our ty "@sig0_fp" shouldBeA[TypeUFuncPtr] { its => its.sig shouldBe (our sig "@sig0") }
    our ty "@sig1_fp" shouldBeA[TypeUFuncPtr] { its => its.sig shouldBe (our sig "@sig1") }
142

143
144
145
146
147
148
    // Testing namespaces
    val i8 = our ty "@i8"
    our anything "@i8" shouldBe i8
    
    val sig0 = our sig "@sig0"
    our anything "@sig0" shouldBe sig0
Kunshan Wang's avatar
Kunshan Wang committed
149
  }
Kunshan Wang's avatar
Kunshan Wang committed
150
  
Kunshan Wang's avatar
Kunshan Wang committed
151
  def validateConstants(bundle: GlobalBundle) {
Kunshan Wang's avatar
Kunshan Wang committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    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
180
181
182
      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
183
184
185
    }
    
    our const "@cs2" shouldBeA[ConstStruct] { its=>
Kunshan Wang's avatar
Kunshan Wang committed
186
187
188
      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
189
190
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
    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
210
211
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
212
213
214
215
216
217
218
219
220
221
222
223
224
    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
225

Kunshan Wang's avatar
Kunshan Wang committed
226
227
228
229
230
231
232
233
234
    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
235
    
236
237
238
239
240
241
242
243
244
    our const "@I32P_PTR1" shouldBeA[ConstPointer] { its =>
      its.constTy shouldBe (our ty "@i32_p")
      its.addr shouldBe 0x123456789abcdef0L
    }
    
    our const "@SIG0FP_PTR1" shouldBeA[ConstPointer] { its =>
      its.constTy shouldBe (our ty "@sig0_fp")
      its.addr shouldBe 0xfedcba9876543210L
    }
Kunshan Wang's avatar
Kunshan Wang committed
245
246
247
248
249
250
251
252
253
254
255
    
    our const "@ary1" shouldBeA[ConstArray] { its =>
      its.constTy shouldBe (our ty "@i32_3_ary")
      its elems 0 shouldBe (our const "@I32_1")
      its elems 1 shouldBe (our const "@I32_2")
      its elems 2 shouldBe (our const "@I32_3")
    }
    
    our const "@VOID" shouldBeA[ConstNull] { its =>
      its.constTy shouldBe (our ty "@void")
    }
256
257

    
Kunshan Wang's avatar
Kunshan Wang committed
258
    // Testing namespaces
259
    val ci8 = our const "@ci8"
Kunshan Wang's avatar
Kunshan Wang committed
260
261
    our globalValue "@ci8" shouldBe ci8
    our value "@ci8" shouldBe ci8
262
    our anything "@ci8" shouldBe ci8
Kunshan Wang's avatar
Kunshan Wang committed
263
    
264
    val gi64 = our globalCell "@gi64"
Kunshan Wang's avatar
Kunshan Wang committed
265
266
    our globalValue "@gi64" shouldBe gi64
    our value "@gi64" shouldBe gi64
267
    our anything "@gi64" shouldBe gi64
Kunshan Wang's avatar
Kunshan Wang committed
268
  }
Kunshan Wang's avatar
Kunshan Wang committed
269

Kunshan Wang's avatar
Kunshan Wang committed
270
  def validateFunctions(bundle: GlobalBundle) {
Kunshan Wang's avatar
Kunshan Wang committed
271
    val our = bundle
Kunshan Wang's avatar
Kunshan Wang committed
272
273
    
    our sig "@foo" shouldBeA[FuncSig] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
274
      its.retTy shouldBe (our ty "@void")
Kunshan Wang's avatar
Kunshan Wang committed
275
276
      its.paramTy shouldBe empty
    }
Kunshan Wang's avatar
Kunshan Wang committed
277

Kunshan Wang's avatar
Kunshan Wang committed
278
    our sig "@bar" shouldBeA[FuncSig] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
279
280
281
      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
282
283
284
    }
    
    our sig "@baz" shouldBeA[FuncSig] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
285
286
287
      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
288
289
290
    }
    
    our sig "@sig_fs" shouldBeA[FuncSig] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
291
292
      its.retTy shouldBe (our ty "@void")
      its paramTy 0 shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
293
294
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
295
    our ty "@sig_t" shouldBeA[TypeFuncRef] { _.sig shouldBe (our sig "@sig_fs") }
Kunshan Wang's avatar
Kunshan Wang committed
296

Kunshan Wang's avatar
Kunshan Wang committed
297
298
299
300
301
302
    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
303
    our func "@signal" shouldBeA[Function] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
304
305
      its.sig shouldBe (our sig "@signal_sig")
      its.versions shouldBe Nil
Kunshan Wang's avatar
Kunshan Wang committed
306
307
308
    }
    
    our const "@zero" shouldBeA[ConstInt] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
309
      its.constTy shouldBe (our ty "@i32")
Kunshan Wang's avatar
Kunshan Wang committed
310
311
312
      its.num shouldBe 0
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
313
    our func "@main" shouldBeA[Function] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
314
      its.sig shouldBe (our sig "@baz")
Kunshan Wang's avatar
Kunshan Wang committed
315
      its.versions.head shouldBe (our funcVer "@main.v1")
Kunshan Wang's avatar
Kunshan Wang committed
316
317
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
318
    our funcVer "@main.v1" shouldBeA[FuncVer] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
319
320
      val theFuncVer = its
      its.sig shouldBe (our sig "@baz")
Kunshan Wang's avatar
Kunshan Wang committed
321
322
323
324
325
326
327
328
329
330
      
      in (its bb "%entry") { my =>
        my norParams 0 shouldBeA[NorParam] { whose =>
          whose.ty shouldBe (our ty "@i32")
          whose.name.get shouldEqual "@main.v1.entry.argc"
        }
        my norParams 1 shouldBeA[NorParam] { whose =>
          whose.ty shouldBe (our ty "@iii8")
          whose.name.get shouldEqual "@main.v1.entry.argv"
        }
Kunshan Wang's avatar
Kunshan Wang committed
331
      }
Kunshan Wang's avatar
Kunshan Wang committed
332
      
Kunshan Wang's avatar
Kunshan Wang committed
333
    }
Kunshan Wang's avatar
Kunshan Wang committed
334
    
335
336
337
338
339
340
    our expFunc "@main_native" shouldBeA[ExposedFunc] { its =>
      its.func shouldBe (our func "@main")
      its.callConv shouldEqual Flag("#DEFAULT")
      its.cookie shouldBe (our const "@zero64").asInstanceOf[ConstInt]
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
341
342
343
344
    // Testing namespaces
    val main = our func "@main"
    our globalValue "@main" shouldBe main
    our value "@main" shouldBe main
345
    our anything "@main" shouldBe main
Kunshan Wang's avatar
Kunshan Wang committed
346
    
Kunshan Wang's avatar
Kunshan Wang committed
347
348
    val mainV1 = our funcVer "@main.v1"
    our anything "@main.v1" shouldBe mainV1
349
350
351
352
353
354
    
    val mainNativeGN = "@main_native"
    val mainNative = our expFunc mainNativeGN
    our globalValue mainNativeGN shouldBe mainNative
    our value mainNativeGN shouldBe mainNative
    our anything mainNativeGN shouldBe mainNative 
Kunshan Wang's avatar
Kunshan Wang committed
355
  }
Kunshan Wang's avatar
Kunshan Wang committed
356
357
358
359

  def in(func: Function)(f: (Function, FuncVer) => Unit) {
    val ver = func.versions.head
    f(func, ver)
Kunshan Wang's avatar
Kunshan Wang committed
360
  }
Kunshan Wang's avatar
Kunshan Wang committed
361
362
363
364

  def in(funcVer: FuncVer)(f: FuncVer => Unit) {
    f(funcVer)
  }
Kunshan Wang's avatar
Kunshan Wang committed
365
  
Kunshan Wang's avatar
Kunshan Wang committed
366
   def in(b: BasicBlock)(f: BasicBlock => Unit) {
Kunshan Wang's avatar
Kunshan Wang committed
367
368
369
    f(b)
  }
  
Kunshan Wang's avatar
Kunshan Wang committed
370
  def validateInstructions(bundle: GlobalBundle) {
Kunshan Wang's avatar
Kunshan Wang committed
371
    val our = bundle
Kunshan Wang's avatar
Kunshan Wang committed
372
    
Kunshan Wang's avatar
Kunshan Wang committed
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
    in (our func "@intBinOpTest") { (func, the) =>
      in (the bb "%entry") { my =>
        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 }
        
        for (i <- my.localVarNs.all; if i.isInstanceOf[InstBinOp]) {
          i.asInstanceOf[InstBinOp].opndTy shouldBe (our ty "@i32")
          i.asInstanceOf[InstBinOp].op1 shouldBe (my param "%p0")
          i.asInstanceOf[InstBinOp].op2 shouldBe (my param "%p1")
        }
Kunshan Wang's avatar
Kunshan Wang committed
394
      }
Kunshan Wang's avatar
Kunshan Wang committed
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
    }
     
    in (our func "@fpBinOpTest") { (func, the) =>
      in(the bb "%entry") {my =>
      
        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 }
        
        for (i <- my.localVarNs.all; if i.isInstanceOf[InstBinOp]) {
          i.asInstanceOf[InstBinOp].opndTy shouldBe (our ty "@double")
          i.asInstanceOf[InstBinOp].op1 shouldBe (my param "%p0")
          i.asInstanceOf[InstBinOp].op2 shouldBe (my param "%p1")
        }
Kunshan Wang's avatar
Kunshan Wang committed
411
412
      }
    }   
Kunshan Wang's avatar
Kunshan Wang committed
413

Kunshan Wang's avatar
Kunshan Wang committed
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
    in (our func "@intCmpTest") { (func, the) =>
      in(the bb "%entry") { my =>
        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 }
        
        for (i <- my.localVarNs.all; if i.isInstanceOf[InstCmp]) {
          i.asInstanceOf[InstCmp].opndTy shouldBe (our ty "@i64")
          i.asInstanceOf[InstCmp].op1 shouldBe (my param "%p0")
          i.asInstanceOf[InstCmp].op2 shouldBe (my param "%p1")
        }
Kunshan Wang's avatar
Kunshan Wang committed
432
433
434
      }
    }   
    
Kunshan Wang's avatar
Kunshan Wang committed
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
    in (our func "@fpCmpTest") { (func, the) =>
      in(the bb "%entry") { my =>
      
        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 }
        
        for (i <- my.localVarNs.all; if i.isInstanceOf[InstCmp]) {
          i.asInstanceOf[InstCmp].opndTy shouldBe (our ty "@float")
          i.asInstanceOf[InstCmp].op1 shouldBe (my param "%p0")
          i.asInstanceOf[InstCmp].op2 shouldBe (my param "%p1")
        }
Kunshan Wang's avatar
Kunshan Wang committed
460
461
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
462

Kunshan Wang's avatar
Kunshan Wang committed
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
    in (our func "@convTest") { (func, the) =>
      in(the bb "%entry") { my =>
      
        my inst "%trunc" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.TRUNC
          its.fromTy shouldBe (our ty "@i64")
          its.toTy   shouldBe (our ty "@i32")
          its.opnd   shouldBe (my param "%p1")
        }
        my inst "%zext" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.ZEXT 
          its.fromTy shouldBe (our ty "@i32")
          its.toTy   shouldBe (our ty "@i64")
          its.opnd   shouldBe (my param "%p0")
  
        }
        my inst "%sext" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.SEXT
          its.fromTy shouldBe (our ty "@i32")
          its.toTy   shouldBe (our ty "@i64")
          its.opnd   shouldBe (my param "%p0")
        }
        my inst "%fptrunc" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.FPTRUNC
          its.fromTy shouldBe (our ty "@double")
          its.toTy   shouldBe (our ty "@float")
          its.opnd   shouldBe (my param "%p3")
        }
        my inst "%fpext" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.FPEXT 
          its.fromTy shouldBe (our ty "@float")
          its.toTy   shouldBe (our ty "@double")
          its.opnd   shouldBe (my param "%p2")
        }
        my inst "%fptoui" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.FPTOUI
          its.fromTy shouldBe (our ty "@double")
          its.toTy   shouldBe (our ty "@i64")
          its.opnd   shouldBe (my param "%p3")
        }
        my inst "%fptosi" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.FPTOSI
          its.fromTy shouldBe (our ty "@double")
          its.toTy   shouldBe (our ty "@i64")
          its.opnd   shouldBe (my param "%p3")
        }
        my inst "%uitofp" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.UITOFP
          its.fromTy shouldBe (our ty "@i64")
          its.toTy   shouldBe (our ty "@double")
          its.opnd   shouldBe (my param "%p1")
        }
        my inst "%sitofp" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.SITOFP 
          its.fromTy shouldBe (our ty "@i64")
          its.toTy   shouldBe (our ty "@double")
          its.opnd   shouldBe (my param "%p1")
        }
        my inst "%bitcast0" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.BITCAST 
          its.fromTy shouldBe (our ty "@i32")
          its.toTy   shouldBe (our ty "@float")
          its.opnd   shouldBe (my param "%p0")
        }
        my inst "%bitcast1" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.BITCAST 
          its.fromTy shouldBe (our ty "@i64")
          its.toTy   shouldBe (our ty "@double")
          its.opnd   shouldBe (my param "%p1")
        }
        my inst "%bitcast2" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.BITCAST 
          its.fromTy shouldBe (our ty "@float")
          its.toTy   shouldBe (our ty "@i32")
          its.opnd   shouldBe (my param "%p2")
        }
        my inst "%bitcast3" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.BITCAST 
          its.fromTy shouldBe (our ty "@double")
          its.toTy   shouldBe (our ty "@i64")
          its.opnd   shouldBe (my param "%p3")
        }
Kunshan Wang's avatar
Kunshan Wang committed
545
546
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
547

Kunshan Wang's avatar
Kunshan Wang committed
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
    in (our func "@refCastTest") { (func, the) =>
      in(the bb "%entry") { my =>
        
        my inst "%refcast" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.REFCAST
          its.fromTy shouldBe (our ty "@rv")
          its.toTy   shouldBe (our ty "@ri32")
          its.opnd   shouldBe (my param "%p0")
        }
        my inst "%irefcast" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.REFCAST
          its.fromTy shouldBe (our ty "@irv")
          its.toTy   shouldBe (our ty "@ii64")
          its.opnd   shouldBe (my param "%p1")
        }
        my inst "%funccast" shouldBeA[InstConv] { its => 
          its.op     shouldBe ConvOptr.REFCAST
          its.fromTy shouldBe (our ty "@npnr_func")
          its.toTy   shouldBe (our ty "@iii_func")
          its.opnd   shouldBe (my param "%p2")
        }
Kunshan Wang's avatar
Kunshan Wang committed
569
570
      }
    }
571
    
Kunshan Wang's avatar
Kunshan Wang committed
572
573
574
575
576
577
578
579
580
581
    in (our func "@ptrCastTest") { (func, the) =>
      in(the bb "%entry") { my =>
        
        my inst "%ptrcast" shouldBeA[InstConv] { its =>
          its.op shouldBe ConvOptr.PTRCAST
          its.fromTy shouldBe (our ty "@i64")
          its.toTy shouldBe (our ty "@pi64")
          its.opnd shouldBe (my param "%p0")
        } 
      }
582
    }
Kunshan Wang's avatar
Kunshan Wang committed
583

Kunshan Wang's avatar
Kunshan Wang committed
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
    in (our func "@ctrlFlow") { (func, the) =>
      in(the bb "%entry") { my =>
        my inst "%br1" shouldBeA[InstBranch] { its =>
          its.dest.bb shouldBe (the bb "%head")
          its.dest.args shouldBe Seq(my value "%p0")
        }
      }
      
      in(the bb "%one") { my =>
        my inst "%br3" shouldBeA[InstBranch] { its =>
          its.dest.bb shouldBe (the bb "%next")
          its.dest.args shouldBe Seq(my value "%x")
        }
      }
      in(the bb "%two") { my =>
        my inst "%br4" shouldBeA[InstBranch] { its =>
          its.dest.bb shouldBe (the bb "%next")
          its.dest.args shouldBe Seq(my value "%x")
        }
      }
      in(the bb "%other") { my =>
        my inst "%br5" shouldBeA[InstBranch] { its =>
          its.dest.bb shouldBe (the bb "%next")
          its.dest.args shouldBe Seq(my value "%x")
        }
      }
      in(the bb "%next") { my =>
        my inst "%br6" shouldBeA[InstBranch] { _.dest.bb shouldBe (the bb "%head") }
      }
        
      in(the bb "%head") { my =>
        my inst "%br2" shouldBeA[InstBranch2] { its =>
          its.cond shouldBe (my inst "%zero")
          its.ifTrue.bb shouldBe (the bb "%body")
          its.ifTrue.args shouldBe Seq(my value "%x")
          its.ifFalse.bb shouldBe (the bb "%exit")
          its.ifFalse.args shouldBe empty
        }
      }
      
      in(the bb "%body") { my =>
        my inst "%switch" shouldBeA[InstSwitch] { its =>
          its.opndTy shouldBe (our ty "@i32")
          its.opnd shouldBe (my inst "%x")
          its.defDest.bb shouldBe (the bb "%other")
          its.cases(0)._1 shouldBe (our value "@I32_1")
          its.cases(0)._2.bb shouldBe (the bb "%one")  
          its.cases(1)._1 shouldBe (our value "@I32_2")
          its.cases(1)._2.bb shouldBe (the bb "%two")  
        }
Kunshan Wang's avatar
Kunshan Wang committed
634
      }
Kunshan Wang's avatar
Kunshan Wang committed
635
636
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
637
638
639
640
641
642
643
    in (our func "@callee2") { (func, the) =>
      in(the bb "%entry") { my =>
        
        my inst "%ret" shouldBeA[InstRet] { its =>
          its.funcVer shouldBe the
          its.retVal shouldBe (my inst "%rv")
        }
Kunshan Wang's avatar
Kunshan Wang committed
644
645
646
      }
    }     
 
Kunshan Wang's avatar
Kunshan Wang committed
647
648
    in (our func "@callee3") { (func, the) =>
      in(the bb "%entry") { my =>
Kunshan Wang's avatar
Kunshan Wang committed
649
      
Kunshan Wang's avatar
Kunshan Wang committed
650
651
652
        my inst "%throw" shouldBeA[InstThrow] { its =>
          its.excVal shouldBe (my inst "%exc")
        }
Kunshan Wang's avatar
Kunshan Wang committed
653
      }
Kunshan Wang's avatar
Kunshan Wang committed
654
    }
Kunshan Wang's avatar
Kunshan Wang committed
655

Kunshan Wang's avatar
Kunshan Wang committed
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
    in (our func "@caller1") { (func, the) =>
      in(the bb "%entry") { my =>
        
        my inst "%v1" shouldBeA[InstCall] { its =>
          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
        }
        
        my inst "%v2" shouldBeA[InstCall] { its =>
          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
        }
  
        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.get.nor.bb shouldBe (the bb "%cont")
          its.excClause.get.nor.args shouldBe Seq(my inst "%v2", my inst "%v3")
          its.excClause.get.exc.bb shouldBe (the bb "%catch")
          its.excClause.get.exc.args shouldBe empty
          its.keepAlives shouldBe empty
        }  
      }
      
      in(the bb "%cont") { my =>
        my inst "%v4" shouldBeA[InstCall] { its =>
          its.sig shouldBe (our sig "@npnr_sig")
          its.callee shouldBe (our globalValue "@callee1")
          its.argList shouldBe empty
          its.excClause shouldBe None
          its.keepAlives shouldBe Seq("%v2", "%v3").map(my.value)
        }
  
        my inst "%v5" shouldBeA[InstCall] { its =>
          its.sig shouldBe (our sig "@iii_sig")
          its.callee shouldBe (our globalValue "@callee3")
          its.argList shouldBe Seq("%v3", "%v3").map(my.value)
          its.excClause.get.nor.bb shouldBe (the bb "%cont2")
          its.excClause.get.nor.args shouldBe empty
          its.excClause.get.exc.bb shouldBe (the bb "%catch")
          its.excClause.get.exc.args shouldBe empty
          its.keepAlives shouldEqual Seq(my value "%v2")
        }  
Kunshan Wang's avatar
Kunshan Wang committed
706
707
      }
      
Kunshan Wang's avatar
Kunshan Wang committed
708
709
710
711
      in(the bb "%cont2") { my =>
        my inst "%retv" shouldBeA[InstRet] {its =>
          its.retVal shouldBe (our value "@VOID")        
        }
Kunshan Wang's avatar
Kunshan Wang committed
712
713
      }
      
Kunshan Wang's avatar
Kunshan Wang committed
714
715
716
      in(the bb "%catch") { my =>
        my.excParam.get shouldBeA[ExcParam] {its =>
        }
Kunshan Wang's avatar
Kunshan Wang committed
717
718
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
719
720
721
722
723
724
725
726
727
    
    in (our func "@caller2") { (func, the) =>
      in(the bb "%entry") { my =>
        
        my inst "%tc" shouldBeA[InstTailCall] { its =>
          its.sig shouldBe (our sig "@iii_sig")
          its.callee shouldBe (our globalValue "@callee2")
          its.argList shouldEqual Seq("%p0", "%p1").map(my.inst)
        }
Kunshan Wang's avatar
Kunshan Wang committed
728
729
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
730

Kunshan Wang's avatar
Kunshan Wang committed
731
    in (our func "@aggregate") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
732
      in(the bb "%entry") { my =>
Kunshan Wang's avatar
Kunshan Wang committed
733
      
Kunshan Wang's avatar
Kunshan Wang committed
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
        my inst "%e0" shouldBeA[InstExtractValue] { its =>
          its.strTy shouldBe (our ty "@sid")
          its.index shouldBe 0
          its.opnd shouldBe (our value "@sid1")
        }
        
        my inst "%e1" shouldBeA[InstExtractValue] { its =>
          its.strTy shouldBe (our ty "@sid")
          its.index shouldBe 1
          its.opnd shouldBe (our value "@sid1")
        }
        
        my inst "%i0" shouldBeA[InstInsertValue] { its =>
          its.strTy shouldBe (our ty "@sid")
          its.index shouldBe 0
          its.opnd shouldBe (our value "@sid1")
          its.newVal shouldBe (our value "@I64_0")
        }
        
        my inst "%i1" shouldBeA[InstInsertValue] { its =>
          its.strTy shouldBe (our ty "@sid")
          its.index shouldBe 1
          its.opnd shouldBe (our value "@sid1")
          its.newVal shouldBe (our value "@D_0")
        }
        
        my inst "%ee0" shouldBeA[InstExtractElement] { its =>
          its.seqTy 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.seqTy 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
782
783
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
784

Kunshan Wang's avatar
Kunshan Wang committed
785
    in (our func "@memops") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
      in(the bb "%entry") { my =>
        
        my inst "%new" shouldBeA[InstNew] { its =>
          its.allocTy shouldBe (our ty "@i64")
          its.excClause shouldBe None
        }
        
        my inst "%newhybrid" shouldBeA[InstNewHybrid] { its =>
          its.allocTy shouldBe (our ty "@hic")
          its.lenTy shouldBe (our ty "@i64")
          its.length shouldBe (my param "%p0")
          its.excClause shouldBe None
        }
        
        my inst "%alloca" shouldBeA[InstAlloca] { its =>
          its.allocTy shouldBe (our ty "@i64")
          its.excClause shouldBe None
        }
        
        my inst "%allocahybrid" shouldBeA[InstAllocaHybrid] { its =>
          its.allocTy shouldBe (our ty "@hic")
          its.lenTy shouldBe (our ty "@i64")
          its.length shouldBe (my param "%p0")
          its.excClause shouldBe None
        }
Kunshan Wang's avatar
Kunshan Wang committed
811

Kunshan Wang's avatar
Kunshan Wang committed
812
813
814
815
816
817
        my inst "%new_s" shouldBeA[InstNew] { its =>
          its.allocTy shouldBe (our ty "@i64")
          its.excClause shouldBe Some(ExcClause(
              DestClause(the bb "%bb2", Seq("%alloca", "%allocahybrid", "%p0", "%p1").map(my.value)),
              DestClause(the bb "%handler", Seq())))
        }
Kunshan Wang's avatar
Kunshan Wang committed
818
      }
Kunshan Wang's avatar
Kunshan Wang committed
819
820
821
822
823
824
825
826
827
828
      in(the bb "%bb2") { my =>
        
        my inst "%newhybrid_s" shouldBeA[InstNewHybrid] { its =>
          its.allocTy shouldBe (our ty "@hic")
          its.lenTy shouldBe (our ty "@i64")
          its.length shouldBe (my param "%p0")
          its.excClause shouldBe Some(ExcClause(
              DestClause(the bb "%bb3", Seq("%alloca", "%allocahybrid", "%p0", "%p1").map(my.value)),
              DestClause(the bb "%handler", Seq())))
        }
Kunshan Wang's avatar
Kunshan Wang committed
829
      }
Kunshan Wang's avatar
Kunshan Wang committed
830
831
832
833
834
835
836
837
      in(the bb "%bb3") { my =>
        
        my inst "%alloca_s" shouldBeA[InstAlloca] { its =>
          its.allocTy shouldBe (our ty "@i64")
          its.excClause shouldBe Some(ExcClause(
              DestClause(the bb "%bb4", Seq("%alloca", "%allocahybrid", "%p0", "%p1").map(my.value)),
              DestClause(the bb "%handler", Seq())))
        }
Kunshan Wang's avatar
Kunshan Wang committed
838
      }
Kunshan Wang's avatar
Kunshan Wang committed
839
840
841
842
843
844
845
846
847
848
      in(the bb "%bb4") { my =>
        
        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(
              DestClause(the bb "%bb5", Seq("%alloca", "%allocahybrid", "%p1").map(my.value)),
              DestClause(the bb "%handler", Seq())))
        }
Kunshan Wang's avatar
Kunshan Wang committed
849
      }
Kunshan Wang's avatar
Kunshan Wang committed
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
      in(the bb "%bb5") { my =>
  
        my inst "%new2" shouldBeA[InstNew] { its =>
          its.allocTy shouldBe (our ty "@sid")
          its.excClause shouldBe None
        }
        
        my inst "%alloca2" shouldBeA[InstAlloca] { its =>
          its.allocTy shouldBe (our ty "@al")
          its.excClause shouldBe None
        }
        
        my inst "%getiref" shouldBeA[InstGetIRef] { its =>
          its.referentTy shouldBe (our ty "@sid")
          its.opnd shouldBe (my inst "%new2")
        }
        
        my inst "%getfieldiref" shouldBeA[InstGetFieldIRef] { its =>
          its.ptr shouldBe false
          its.referentTy shouldBe (our ty "@sid")
          its.index shouldBe 0
          its.opnd shouldBe (my inst "%getiref")
        }
        
        my inst "%getelemiref" shouldBeA[InstGetElemIRef] { its =>
          its.ptr shouldBe false
          its.referentTy shouldBe (our ty "@al")
          its.indTy shouldBe (our ty "@i64")
          its.opnd shouldBe (my inst "%alloca2")
          its.index shouldBe (my param "%p1")
        }
        
        my inst "%shiftiref" shouldBeA[InstShiftIRef] { its =>
          its.ptr shouldBe false
          its.referentTy shouldBe (our ty "@i8")
          its.offTy shouldBe (our ty "@i64")
          its.opnd shouldBe (my inst "%getvarpartiref")
          its.offset shouldBe (my param "%p1")
        }
  
        my inst "%getfixedpartiref" shouldBeA[InstGetFixedPartIRef] { its =>
          its.ptr shouldBe false
          its.referentTy shouldBe (our ty "@hic")
          its.opnd shouldBe (my inst "%allocahybrid")
        }
        
        my inst "%getvarpartiref" shouldBeA[InstGetVarPartIRef] { its =>
          its.ptr shouldBe false
          its.referentTy shouldBe (our ty "@hic")
          its.opnd shouldBe (my inst "%allocahybrid")
        }
        
        my inst "%load" shouldBeA[InstLoad] { its =>
          its.ptr shouldBe false
          its.ord shouldBe MemoryOrder.NOT_ATOMIC
          its.referentTy shouldBe (our ty "@i64")
          its.loc shouldBe (my inst "%alloca")
          its.excClause shouldBe None
        }
        
        my inst "%store" shouldBeA[InstStore] { its =>
          its.ptr shouldBe false
          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 None
        }
        
        my inst "%cmpxchg" shouldBeA[InstCmpXchg] { its =>
          its.ptr shouldBe false
          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 None
        }
Kunshan Wang's avatar
Kunshan Wang committed
929
      
Kunshan Wang's avatar
Kunshan Wang committed
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
        my inst "%atomicrmw" shouldBeA[InstAtomicRMW] { its =>
          its.ptr shouldBe false
          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 None
        }
     
        my inst "%load_s" shouldBeA[InstLoad] { its =>
          its.ptr shouldBe false
          its.ord shouldBe MemoryOrder.NOT_ATOMIC
          its.referentTy shouldBe (our ty "@i64")
          its.loc shouldBe (my inst "%alloca")
          its.excClause shouldBe Some(ExcClause(
              DestClause(the bb "%bb6", Seq(my value "%alloca")),
              DestClause(the bb "%handler", Seq())))
        }
Kunshan Wang's avatar
Kunshan Wang committed
949
      }
Kunshan Wang's avatar
Kunshan Wang committed
950
951
952
953
954
955
956
957
958
959
960
961
      in(the bb "%bb6") { my =>
        
        my inst "%store_s" shouldBeA[InstStore] { its =>
          its.ptr shouldBe false
          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(
              DestClause(the bb "%bb7", Seq(my value "%alloca" )),
              DestClause(the bb "%handler", Seq())))
        }
Kunshan Wang's avatar
Kunshan Wang committed
962
      }
Kunshan Wang's avatar
Kunshan Wang committed
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
      in(the bb "%bb7") { my =>
        
        my inst "%cmpxchg_s" shouldBeA[InstCmpXchg] { its =>
          its.ptr shouldBe false
          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(
              DestClause(the bb "%bb8", Seq(my value "%alloca")),
              DestClause(the bb "%handler", Seq())))
       }
      }
      in(the bb "%bb8") { my =>
Kunshan Wang's avatar
Kunshan Wang committed
979
      
Kunshan Wang's avatar
Kunshan Wang committed
980
981
982
983
984
985
986
987
988
989
990
        my inst "%atomicrmw_s" shouldBeA[InstAtomicRMW] { its =>
          its.ptr shouldBe false
          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(
              DestClause(the bb "%bb9", Seq()),
              DestClause(the bb "%handler", Seq())))
        }
Kunshan Wang's avatar
Kunshan Wang committed
991
      }
Kunshan Wang's avatar
Kunshan Wang committed
992
993
994
995
996
      in(the bb "%bb9") { my =>
        
        my inst "%fence" shouldBeA[InstFence] { its =>
          its.ord shouldBe (MemoryOrder.SEQ_CST)
        }
Kunshan Wang's avatar
Kunshan Wang committed
997
998
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
999

Kunshan Wang's avatar
Kunshan Wang committed
1000
    in (our func "@memops_ptr") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
      in(the bb "%entry") { my =>
        
        my inst "%p" shouldBeA[InstCommInst] { _.argList(0) shouldBe (my inst "%new")}
        
        my inst "%getfieldiref" shouldBeA[InstGetFieldIRef] { its =>
          its.ptr shouldBe true
          its.referentTy shouldBe (our ty "@sid")
          its.index shouldBe 0
          its.opnd shouldBe (my inst "%p2")
        }
        
        my inst "%getelemiref" shouldBeA[InstGetElemIRef] { its =>
          its.ptr shouldBe true
          its.referentTy shouldBe (our ty "@al")
          its.indTy shouldBe (our ty "@i64")
          its.opnd shouldBe (my inst "%p3")
          its.index shouldBe (my param "%p1")
        }
        
        my inst "%shiftiref" shouldBeA[InstShiftIRef] { its =>
          its.ptr shouldBe true
          its.referentTy shouldBe (our ty "@i8")
          its.offTy shouldBe (our ty "@i64")
          its.opnd shouldBe (my inst "%getvarpartiref")
          its.offset shouldBe (my param "%p1")
        }
  
        my inst "%getfixedpartiref" shouldBeA[InstGetFixedPartIRef] { its =>
          its.ptr shouldBe true
          its.referentTy shouldBe (our ty "@hic")
          its.opnd shouldBe (my inst "%ph")
        }
        
        my inst "%getvarpartiref" shouldBeA[InstGetVarPartIRef] { its =>
          its.ptr shouldBe true
          its.referentTy shouldBe (our ty "@hic")
          its.opnd shouldBe (my inst "%ph")
        }
        
        my inst "%load" shouldBeA[InstLoad] { its =>
          its.ptr shouldBe true
          its.ord shouldBe MemoryOrder.NOT_ATOMIC
          its.referentTy shouldBe (our ty "@i64")
          its.loc shouldBe (my inst "%p")
          its.excClause shouldBe None
        }
        
        my inst "%store" shouldBeA[InstStore] { its =>
          its.ptr shouldBe true
          its.ord shouldBe MemoryOrder.NOT_ATOMIC
          its.referentTy shouldBe (our ty "@i64")
          its.loc shouldBe (my inst "%p")
          its.newVal shouldBe (our const "@I64_42")
          its.excClause shouldBe None
        }
        
        my inst "%cmpxchg" shouldBeA[InstCmpXchg] { its =>
          its.ptr shouldBe true
          its.ordSucc shouldBe MemoryOrder.SEQ_CST
          its.ordFail shouldBe MemoryOrder.SEQ_CST
          its.referentTy shouldBe (our ty "@i64")
          its.loc shouldBe (my inst "%p")
          its.expected shouldBe (our const "@I64_42")
          its.desired shouldBe (our const "@I64_0")
          its.excClause shouldBe None
        }
1067
      
Kunshan Wang's avatar
Kunshan Wang committed
1068
1069
1070
1071
1072
1073
1074
1075
1076
        my inst "%atomicrmw" shouldBeA[InstAtomicRMW] { its =>
          its.ptr shouldBe true
          its.ord shouldBe MemoryOrder.SEQ_CST
          its.op shouldBe AtomicRMWOptr.ADD
          its.referentTy shouldBe (our ty "@i64")
          its.loc shouldBe (my inst "%p")
          its.opnd shouldBe (our const "@I64_43")
          its.excClause shouldBe None
        }
1077
1078
1079
      }
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
1080
    in (our func "@memorder") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
      in(the bb "%entry") { my =>
        
        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
1093
      }
Kunshan Wang's avatar
Kunshan Wang committed
1094
1095
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
1096
    in (our func "@atomicrmwops") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
      in(the bb "%entry") { my =>
        
        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
1111
    }
Kunshan Wang's avatar
Kunshan Wang committed
1112

Kunshan Wang's avatar
Kunshan Wang committed
1113
    in (our func "@traps") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
      in(the bb "%entry") { my =>
        
        my inst "%tp" shouldBeA[InstTrap] { its =>
          its.retTy shouldBe (our ty "@i32")
          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(
              DestClause(the bb "%tp_s_cont", Seq("%a", "%b").map(my.value)),
              DestClause(the bb "%tp_s_exc", Seq())))
          its.keepAlives shouldBe Seq(my inst "%b")
        }
Kunshan Wang's avatar
Kunshan Wang committed
1129
      }
Kunshan Wang's avatar
Kunshan Wang committed
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
      in(the bb "%tp_s_cont") { my =>
        
        my inst "%wp" shouldBeA[InstWatchPoint] { its =>
          its.wpID shouldBe 1
          its.retTy shouldBe (our ty "@float")
          its.dis shouldBe DestClause(the bb "%wp_dis_cont", Seq("%b").map(my.value))
          its.ena shouldBe DestClause(the bb "%wp_ena_cont", Seq())
          its.exc shouldBe None
          its.keepAlives shouldBe Seq(my inst "%a")
        }
Kunshan Wang's avatar
Kunshan Wang committed
1140
      }
Kunshan Wang's avatar
Kunshan Wang committed
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
      in(the bb "%wp_dis_cont") { my =>
        
        my inst "%wp_s" shouldBeA[InstWatchPoint] { its =>
          its.wpID shouldBe 2
          its.retTy shouldBe (our ty "@double")
          its.dis shouldBe DestClause(the bb "%wp_s_dis_cont", Seq())
          its.ena shouldBe DestClause(the bb "%wp_s_ena_cont", Seq())
          its.exc shouldBe Some(DestClause(the bb "%wp_s_exc", Seq()))
          its.keepAlives shouldBe Seq(my inst "%b")
        }
Kunshan Wang's avatar
Kunshan Wang committed
1151
      }
Kunshan Wang's avatar
Kunshan Wang committed
1152
    }
Kunshan Wang's avatar
Kunshan Wang committed
1153

Kunshan Wang's avatar
Kunshan Wang committed
1154
    in (our func "@ccall") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
1155
      in(the bb "%entry") { my =>
Kunshan Wang's avatar
Kunshan Wang committed
1156
      
Kunshan Wang's avatar
Kunshan Wang committed
1157
1158
1159
1160
1161
1162
1163
        my inst "%rv" shouldBeA[InstCCall] { its =>
          its.callConv shouldBe Flag("#DEFAULT")
          its.funcTy shouldBe (our ty "@ccall_callee_fp")
          its.sig shouldBe (our sig "@ccall_callee_sig")
          its.callee shouldBe (my param "%p0")
          its.argList shouldBe Seq(our value "@D_1")
        }
Kunshan Wang's avatar
Kunshan Wang committed
1164
1165
1166
      }
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
1167
    in (our func "@gen") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
      in(the bb "%entry") { my =>
        
        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
        }
        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
1184
1185
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
1186
   
Kunshan Wang's avatar
Kunshan Wang committed
1187
    in (our func "@swapstack") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
      in(the bb "%entry") { my =>
        
        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
        }
        
        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(
              DestClause(the bb "%cont", Seq("%curstack", "%coro").map(my.value)),
              DestClause(the bb "%exc", Seq())))
        }
      }  
      in(the bb "%cont") { my =>
        my inst "%ss1" shouldBeA[InstSwapStack] { its =>
          its.swappee shouldBe (my value "%coro")
          its.curStackAction shouldBe RetWith(our ty "@i64")
          its.newStackAction shouldBe PassValue(our ty "@void", our const "@VOID")
          its.excClause shouldBe None
          its.keepAlives shouldBe Seq(my value "%curstack")
        }
        my inst "%ss2" shouldBeA[InstSwapStack] { its =>
          its.swappee shouldBe (my value "%coro")
          its.curStackAction shouldBe RetWith(our ty "@i64")
          its.newStackAction shouldBe PassValue(our ty "@void", our const "@VOID")
          its.excClause shouldBe Some(ExcClause(
              DestClause(the bb "%nor", Seq()),
              DestClause(the bb "%exc", Seq())))
          its.keepAlives shouldBe empty
        }
Kunshan Wang's avatar
Kunshan Wang committed
1224
      }
Kunshan Wang's avatar
Kunshan Wang committed
1225
1226
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
1227
    in (our func "@comminst") { (func, the) =>
Kunshan Wang's avatar
Kunshan Wang committed
1228
      in(the bb "%entry") { my =>
Kunshan Wang's avatar
Kunshan Wang committed
1229
      
Kunshan Wang's avatar
Kunshan Wang committed
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
        my inst "%thr" shouldBeA[InstCommInst] { its =>
          its.inst shouldBe CommInsts("@uvm.new_thread")
          its.flagList shouldBe empty
          its.typeList shouldBe empty
          its.funcSigList shouldBe empty
          its.argList shouldBe Seq(my value "%sta")
          its.excClause shouldBe None
          its.keepAlives shouldBe empty
        }
        
        my inst "%th_ex" shouldBeA[InstCommInst] { its =>
          its.inst shouldBe CommInsts("@uvm.thread_exit")
          its.flagList shouldBe empty
          its.typeList shouldBe empty
          its.funcSigList shouldBe empty
          its.argList shouldBe empty
          its.excClause shouldBe None
          its.keepAlives shouldBe empty
        }
  
        my inst "%ex" shouldBeA[InstCommInst] { its =>
          its.inst shouldBe CommInsts("@uvm.native.expose")
          its.flagList shouldBe Seq(Flag("#DEFAULT"))
          its.typeList shouldBe empty
          its.funcSigList shouldBe Seq(our sig "@npnr_sig")
          its.argList shouldBe Seq(our func "@swapstack")
          its.excClause shouldBe None
          its.keepAlives shouldBe empty
        }
1259
      }
Kunshan Wang's avatar
Kunshan Wang committed
1260
    }
Kunshan Wang's avatar
Kunshan Wang committed
1261
  }
Kunshan Wang's avatar
Kunshan Wang committed
1262

Kunshan Wang's avatar
Kunshan Wang committed
1263
1264
1265
1266
  def validateRedef(globalBundle: GlobalBundle, b1: TrantientBundle, b2: TrantientBundle) {
    val ourGlobal = globalBundle
    val ourOld = b1
    val ourNew = b2
Kunshan Wang's avatar
Kunshan Wang committed
1267
    
Kunshan Wang's avatar
Kunshan Wang committed
1268
1269
    in (ourGlobal func "@meaning_of_life") { (func, the) =>
      in (the bb "%entry") { my =>
Kunshan Wang's avatar
Kunshan Wang committed
1270
      
Kunshan Wang's avatar
Kunshan Wang committed
1271
1272
1273
        my inst "%ret" shouldBeA[InstRet] { its =>
          its.retVal shouldBe (ourOld const "@I64_42")
        }
Kunshan Wang's avatar
Kunshan Wang committed
1274
      }
Kunshan Wang's avatar
Kunshan Wang committed
1275
1276
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
1277
1278
1279
1280
1281
1282
1283
1284
    (ourGlobal func "@foxsay").versions shouldBe Nil
    (ourGlobal func "@meaning_of_life").versions shouldBe Seq(ourGlobal funcVer "@meaning_of_life.v1")
     
    ourNew.funcNs.get("@foxsay") shouldBe None
    ourNew.funcNs.get("@meaning_of_life") shouldBe None
   
    (ourNew funcVer "@meaning_of_life.v2").func shouldBe (ourGlobal func "@meaning_of_life")
    (ourNew funcVer "@foxsay.v1").func shouldEqual (ourGlobal func "@foxsay")
Kunshan Wang's avatar
Kunshan Wang committed
1285
    
Kunshan Wang's avatar
Kunshan Wang committed
1286
1287
    in (ourNew funcVer "@meaning_of_life.v2") { the =>
      in (the bb "%entry") { my =>
Kunshan Wang's avatar
Kunshan Wang committed
1288
      
Kunshan Wang's avatar
Kunshan Wang committed
1289
1290
1291
        my inst "%ret" shouldBeA[InstRet] { its =>
          its.retVal shouldBe (ourNew const "@I64_43")
        }
Kunshan Wang's avatar
Kunshan Wang committed
1292
1293
1294
      }
    }
    
Kunshan Wang's avatar
Kunshan Wang committed
1295
1296
    in (ourNew funcVer "@foxsay.v1") {  the =>
      in (the bb "%entry") { my =>
Kunshan Wang's avatar
Kunshan Wang committed
1297
      
Kunshan Wang's avatar
Kunshan Wang committed
1298
1299
1300
        my inst "%ret" shouldBeA[InstRet] { its =>
          its.retVal shouldBe (ourNew const "@I64_99")
        }
Kunshan Wang's avatar
Kunshan Wang committed
1301
      }
Kunshan Wang's avatar
Kunshan Wang committed
1302
1303
    }
  }
Kunshan Wang's avatar
Kunshan Wang committed
1304
  
Kunshan Wang's avatar
Kunshan Wang committed
1305
1306
1307
1308
  def validateRedefAfterMerge(globalBundle: Bundle, bundle: Bundle) {
    val ourGlobal = globalBundle
    val ourNew = bundle
    
Kunshan Wang's avatar
Kunshan Wang committed
1309
1310
1311
    (ourGlobal func "@foxsay").versions.head shouldBe (ourNew funcVer "@foxsay.v1")
    (ourGlobal func "@meaning_of_life").versions.head shouldBe (ourNew funcVer "@meaning_of_life.v2")
    (ourGlobal func "@meaning_of_life").versions.tail.head shouldBe (ourGlobal funcVer "@meaning_of_life.v1")
Kunshan Wang's avatar
Kunshan Wang committed
1312
    
Kunshan Wang's avatar
Kunshan Wang committed
1313
1314
    (ourGlobal funcVer "@meaning_of_life.v1").func shouldBe (ourGlobal func "@meaning_of_life")
    (ourGlobal funcVer "@meaning_of_life.v2").func shouldBe (ourGlobal func "@meaning_of_life")
1315
    
Kunshan Wang's avatar
Kunshan Wang committed
1316
1317
1318
    val foxSay = ourGlobal func "@foxsay"
    ourGlobal value "@foxsay" shouldBe foxSay
    ourGlobal globalValue "@foxsay" shouldBe foxSay
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
    
    {
      val its = ourGlobal expFunc "@meaning_external1"
      its.func shouldBe (ourGlobal func "@meaning_of_life")
      its.callConv shouldBe Flag("#DEFAULT")
      its.cookie shouldBe (ourGlobal const "@I64_42")
    }

    {
      val its = ourGlobal expFunc "@meaning_external2"
      its.func shouldBe (ourGlobal func "@meaning_of_life")
      its.callConv shouldBe Flag("#DEFAULT")
      its.cookie shouldBe (ourGlobal const "@I64_43")
    }
Kunshan Wang's avatar
Kunshan Wang committed
1333
  }
Kunshan Wang's avatar
Kunshan Wang committed
1334
}