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

3 4 5 6 7 8 9 10 11 12 13 14 15
import org.scalatest._

import uvm._
import uvm.types._
import uvm.ssavalues._
import uvm.ifuncs._

trait TestingBundlesValidators extends Matchers with ExtraMatchers {
  
  implicit class MagicalOur(b: Bundle) {
    def ty = b.typeNs
    def const = b.globalValueNS
    def globalValue = b.globalValueNS
Kunshan Wang's avatar
Kunshan Wang committed
16
    def globalData = b.globalDataNS
17 18 19 20
    def sig = b.funcSigNs
    def func = b.funcNs
  }

Kunshan Wang's avatar
Kunshan Wang committed
21 22 23 24 25 26 27
  implicit class MagicalMy(c: CFG) {
    def bb = c.bbNs
    def localValue = c.lvNs
    def param = c.lvNs
    def inst = c.lvNs
  }

28 29 30
  def validateTypes(bundle: Bundle) {
    val our = bundle
    
Kunshan Wang's avatar
Kunshan Wang committed
31 32 33 34 35
    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)
36 37 38 39 40 41 42 43
    
    our ty "@f" shouldBeA[TypeFloat] thatsIt
    our ty "@d" shouldBeA[TypeDouble] thatsIt
    
    our ty "@rv" shouldBeA[TypeRef] { _.ty shouldBeA[TypeVoid] thatsIt }
    our ty "@irv" shouldBeA[TypeIRef] { _.ty shouldBeA[TypeVoid] thatsIt }
    our ty "@wrv" shouldBeA[TypeWeakRef] { _.ty shouldBeA[TypeVoid] thatsIt }
    
Kunshan Wang's avatar
Kunshan Wang committed
44 45
    our ty "@ri16" shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(16)}
    our ty "@ri16_2" shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(16)}
46 47 48

    our ty "@s0" shouldBeA[TypeStruct] { _.fieldTy shouldBe empty }
    our ty "@s1" shouldBeA[TypeStruct] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
49 50 51 52
      its fieldTy 0 shouldBeATypeIntOf(8)
      its fieldTy 1 shouldBeATypeIntOf(16)
      its fieldTy 2 shouldBeATypeIntOf(32)
      its fieldTy 3 shouldBeATypeIntOf(64)
53 54 55 56 57
      its fieldTy 4 shouldBeA[TypeFloat] thatsIt
      its fieldTy 5 shouldBeA[TypeDouble] thatsIt
      its fieldTy 6 shouldBeA[TypeRef] { _.ty shouldBeA[TypeVoid] thatsIt }
      its fieldTy 7 shouldBeA[TypeIRef] { _.ty shouldBeA[TypeVoid] thatsIt }
      its fieldTy 8 shouldBeA[TypeWeakRef] { _.ty shouldBeA[TypeVoid] thatsIt }
Kunshan Wang's avatar
Kunshan Wang committed
58 59
      its fieldTy 9 shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(16)}
      its fieldTy 10 shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(16)}
60 61 62
    }
    
    our ty "@cons" shouldBeA[TypeStruct] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
63
      its fieldTy 0 shouldBeATypeIntOf(64)
64 65 66 67
      its fieldTy 1 shouldBeA[TypeRef] { _.ty shouldBe (our ty "@cons")}
    }
    
    our ty "@a0" shouldBeA[TypeArray] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
68
      its.elemTy shouldBeATypeIntOf(8)
69 70 71 72 73
      its.len shouldEqual 100
    }
    our ty "@a1" shouldBeA[TypeArray] { its =>
      its.elemTy shouldBeA[TypeStruct] { whose =>
        whose fieldTy 0 shouldBeA[TypeDouble] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
74
        whose fieldTy 1 shouldBeATypeIntOf(64)
75 76 77 78 79 80 81 82 83 84
      }
      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 =>
      its.fixedPart shouldBeA[TypeVoid] thatsIt
Kunshan Wang's avatar
Kunshan Wang committed
85
      its.varPart shouldBeATypeIntOf(8)
86 87 88 89 90 91 92
    }
    our ty "@h1" shouldBeA[TypeHybrid] { its =>
      its.fixedPart shouldBeA[TypeStruct] { whose =>
        whose fieldTy 0 shouldBe (our ty "@i32")
        whose fieldTy 1 shouldBe (our ty "@i32")
        whose fieldTy 2 shouldBeA[TypeFloat] thatsIt
      }
Kunshan Wang's avatar
Kunshan Wang committed
93
      its.varPart shouldBeATypeIntOf(64)
94 95 96 97 98 99 100 101 102
    }
    
    our ty "@v" shouldBeA[TypeVoid] thatsIt
    
    our ty "@f0" shouldBeA[TypeFunc] { its =>
      its.sig.retTy shouldBeA[TypeVoid] thatsIt
      its.sig.paramTy shouldBe empty
    }
    our ty "@f1" shouldBeA[TypeFunc] { its =>
Kunshan Wang's avatar
Kunshan Wang committed
103 104
      its.sig.retTy shouldBeATypeIntOf(32)
      its.sig paramTy 0 shouldBeATypeIntOf(32)
105
      its.sig.paramTy(1) shouldBeA[TypeIRef] { _.ty shouldBeA[TypeIRef] {
Kunshan Wang's avatar
Kunshan Wang committed
106
        _.ty shouldBeATypeIntOf(8)}
107 108 109 110 111 112
      }
    }
    
    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
113
  }
Kunshan Wang's avatar
Kunshan Wang committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
  
  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=>
      its.constTy shouldBeA[TypeStruct] { whose =>
        whose fieldTy 0 shouldBeATypeIntOf(64)
        whose fieldTy 1 shouldBeA[TypeDouble] thatsIt
      }
      its fields 0 shouldBeAConstIntOf (64, 100)
      its fields 1 shouldBeAConstDoubleOf 200.0D
    }
    
    our const "@cs2" shouldBeA[ConstStruct] { its=>
      its.constTy shouldBeA[TypeStruct] { whose =>
        whose fieldTy 0 shouldBeA[TypeDouble] thatsIt
        whose fieldTy 1 shouldBeA[TypeStruct] { where =>
          where fieldTy 0 shouldBeA[TypeFloat] thatsIt
          where fieldTy 1 shouldBeATypeIntOf(64)
        }
        whose fieldTy 2 shouldBeATypeIntOf(32)
      }
      its fields 0 shouldBeAConstDoubleOf 1.0D
      its fields 1 shouldBeA[ConstStruct] { whose =>
        whose fields 0 shouldBeAConstFloatOf 2.0F
        whose fields 1 shouldBeAConstIntOf (64, 3)
      }
      its fields 2 shouldBeAConstIntOf (32, 4)
    }
    
    our const "@cons" shouldBeA[ConstStruct] { its =>
      its.constTy shouldBe (our ty "@Cons")
      its fields 0 shouldBeAConstIntOf (64, 42)
      its fields 1 shouldBeA[ConstNull] { _.ty shouldBeA[TypeRef] { _.ty shouldBe (our ty "@Cons") }}
    }
    
    our const "@cr" shouldBeA[ConstNull] { _.ty shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf(64) }}
    our const "@cir" shouldBeA[ConstNull] { _.ty shouldBeA[TypeIRef] { _.ty shouldBeA[TypeFloat] thatsIt }}
    our const "@cwr" shouldBeA[ConstNull] { _.ty shouldBeA[TypeWeakRef] { _.ty shouldBe (our ty "@Cons") }}
    our const "@cfu" shouldBeA[ConstNull] { _.ty shouldBeA[TypeFunc] { _.sig shouldBeA[FuncSig] { its =>
      its.retTy shouldBeA[TypeVoid] thatsIt
      its.paramTy shouldBe empty
    }}}
    our const "@cth" shouldBeA[ConstNull] { _.ty shouldBeA[TypeThread] thatsIt }
    our const "@cst" shouldBeA[ConstNull] { _.ty shouldBeA[TypeStack] thatsIt }
    
    our globalData "@gi64" shouldBeA[GlobalData] { _.ty shouldBeATypeIntOf(64) }

    our func "@fdummy" shouldBeA[Function] { _.sig shouldBeA[FuncSig] { its =>
      its.retTy shouldBeA[TypeVoid] thatsIt
      its.paramTy shouldBe empty
    }}
  }
  def validateFunctions(bundle: Bundle) {
    val our = bundle
Kunshan Wang's avatar
Kunshan Wang committed
194 195 196 197 198
    
    our sig "@foo" shouldBeA[FuncSig] { its =>
      its.retTy shouldBeA[TypeVoid] thatsIt
      its.paramTy shouldBe empty
    }
Kunshan Wang's avatar
Kunshan Wang committed
199

Kunshan Wang's avatar
Kunshan Wang committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
    our sig "@bar" shouldBeA[FuncSig] { its =>
      its.retTy shouldBeATypeIntOf 64
      its paramTy 0 shouldBeATypeIntOf 32
      its paramTy 1 shouldBeATypeIntOf 16
    }
    
    our sig "@baz" shouldBeA[FuncSig] { its =>
      its.retTy shouldBeATypeIntOf 32
      its paramTy 0 shouldBeATypeIntOf 32
      its paramTy 1 shouldBeA[TypeIRef] { _.ty shouldBeA[TypeIRef] {
        _.ty shouldBeATypeIntOf 8
      }}
    }
    
    our sig "@sig_fs" shouldBeA[FuncSig] { its =>
      its.retTy shouldBeA[TypeVoid] thatsIt
      its paramTy 0 shouldBeATypeIntOf 32
    }
    
    our ty "@sig_t" shouldBeA[TypeFunc] { _.sig shouldBe (our sig "@sig_fs") }

    our func "@signal" shouldBeA[Function] { its =>
      its.cfg shouldBe None
      its.sig shouldBeA[FuncSig] { whose =>
        whose.retTy shouldBe (our ty "@sig_t")
        whose paramTy 0 shouldBeATypeIntOf 32
        whose paramTy 1 shouldBe (our ty "@sig_t")
      }
    }
    
    our const "@zero" shouldBeA[ConstInt] { its =>
      its.constTy shouldBeATypeIntOf 32
      its.num shouldBe 0
    }
    
    our func "@main" shouldBeA[Function] { theFunc =>
      val its = theFunc
Kunshan Wang's avatar
Kunshan Wang committed
237
      its.sig shouldBe (our sig "@baz")
Kunshan Wang's avatar
Kunshan Wang committed
238 239 240
      its.cfg shouldNot be(None)
      its.cfg.get.func shouldBe theFunc
      its.cfg.get.params(0).name shouldBe Some("%argc")
Kunshan Wang's avatar
Kunshan Wang committed
241 242
      its.cfg.get.params(0).sig shouldBe its.sig
      its.cfg.get.params(0).index shouldBe 0
Kunshan Wang's avatar
Kunshan Wang committed
243
      its.cfg.get.params(1).name shouldBe Some("%argv")
Kunshan Wang's avatar
Kunshan Wang committed
244 245
      its.cfg.get.params(1).sig shouldBe its.sig
      its.cfg.get.params(1).index shouldBe 1
Kunshan Wang's avatar
Kunshan Wang committed
246 247 248 249 250 251 252 253 254 255 256 257
      its.cfg.get.entry.name shouldBe Some("%entry")
      its.cfg.get.bbs.size shouldBe 1
      
    }
    
    our func "@implicitentry" shouldBeA[Function] { its =>
      its.cfg shouldNot be(None)
      its.sig shouldBe (our sig "@foo")
      its.cfg.get.params shouldBe empty
      its.cfg.get.entry.name shouldBe None
      its.cfg.get.bbs.size shouldBe 1
    }
Kunshan Wang's avatar
Kunshan Wang committed
258
  }
Kunshan Wang's avatar
Kunshan Wang committed
259
  
Kunshan Wang's avatar
Kunshan Wang committed
260 261 262 263 264
  def in(func: Function)(f: (Function, CFG) => Unit) {
    val cfg = func.cfg.get
    f(func, cfg)
  }
  
Kunshan Wang's avatar
Kunshan Wang committed
265 266
  def validateInstructions(bundle: Bundle) {
    val our = bundle
Kunshan Wang's avatar
Kunshan Wang committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
    
    in (our func "@intBinOpTest") { (func, cfg) =>
      val my = cfg
      
      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.inst.all; if i.isInstanceOf[InstBinOp]) {
        i.asInstanceOf[InstBinOp].opndTy shouldBeATypeIntOf 32
        i.asInstanceOf[InstBinOp].op1 shouldBe (my param "%p0")
        i.asInstanceOf[InstBinOp].op2 shouldBe (my param "%p1")
        i.asInstanceOf[InstBinOp].ty shouldBeATypeIntOf 32
      }
    }   
 
    in (our func "@fpBinOpTest") { (func, cfg) =>
      val my = cfg
      
      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.inst.all; if i.isInstanceOf[InstBinOp]) {
        i.asInstanceOf[InstBinOp].opndTy shouldBeA[TypeDouble] thatsIt
        i.asInstanceOf[InstBinOp].op1 shouldBe (my param "%p0")
        i.asInstanceOf[InstBinOp].op2 shouldBe (my param "%p1")
        i.asInstanceOf[InstBinOp].ty shouldBeA[TypeDouble] thatsIt
      }
    }   
    
    in (our func "@intCmpTest") { (func, cfg) =>
      val my = cfg
      
      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.inst.all; if i.isInstanceOf[InstCmp]) {
        i.asInstanceOf[InstCmp].opndTy shouldBeATypeIntOf 64
        i.asInstanceOf[InstCmp].op1 shouldBe (my param "%p0")
        i.asInstanceOf[InstCmp].op2 shouldBe (my param "%p1")
        i.asInstanceOf[InstCmp].ty shouldBeATypeIntOf 1
      }
    }   
    
    in (our func "@fpCmpTest") { (func, cfg) =>
      val my = cfg
      
      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.inst.all; if i.isInstanceOf[InstCmp]) {
        i.asInstanceOf[InstCmp].opndTy shouldBeA[TypeFloat] thatsIt
        i.asInstanceOf[InstCmp].op1 shouldBe (my param "%p0")
        i.asInstanceOf[InstCmp].op2 shouldBe (my param "%p1")
        i.asInstanceOf[InstCmp].ty shouldBeATypeIntOf 1
      }
    }
    
    in (our func "@convTest") { (func, cfg) =>
      val my = cfg
      
      my inst "%trunc" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.TRUNC
        its.fromTy shouldBeATypeIntOf 64
        its.toTy   shouldBeATypeIntOf 32
        its.opnd   shouldBe (my param "%p1")
        its.ty     shouldBeATypeIntOf 32
      }
      my inst "%zext" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.ZEXT 
        its.fromTy shouldBeATypeIntOf 32
        its.toTy   shouldBeATypeIntOf 64
        its.opnd   shouldBe (my param "%p0")
        its.ty     shouldBeATypeIntOf 64
      }
      my inst "%sext" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.SEXT
        its.fromTy shouldBeATypeIntOf 32
        its.toTy   shouldBeATypeIntOf 64
        its.opnd   shouldBe (my param "%p0")
        its.ty     shouldBeATypeIntOf 64
      }
      my inst "%fptrunc" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FPTRUNC
        its.fromTy shouldBeA[TypeDouble] thatsIt
        its.toTy   shouldBeA[TypeFloat] thatsIt
        its.opnd   shouldBe (my param "%p3")
        its.ty     shouldBeA[TypeFloat] thatsIt
      }
      my inst "%fpext" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FPEXT 
        its.fromTy shouldBeA[TypeFloat] thatsIt
        its.toTy   shouldBeA[TypeDouble] thatsIt
        its.opnd   shouldBe (my param "%p2")
        its.ty     shouldBeA[TypeDouble] thatsIt
      }
      my inst "%fptoui" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FPTOUI
        its.fromTy shouldBeA[TypeDouble] thatsIt
        its.toTy   shouldBeATypeIntOf 64
        its.opnd   shouldBe (my param "%p3")
        its.ty     shouldBeATypeIntOf 64
      }
      my inst "%fptosi" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FPTOSI
        its.fromTy shouldBeA[TypeDouble] thatsIt
        its.toTy   shouldBeATypeIntOf 64
        its.opnd   shouldBe (my param "%p3")
        its.ty     shouldBeATypeIntOf 64
      }
      my inst "%uitofp" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.UITOFP
        its.fromTy shouldBeATypeIntOf 64
        its.toTy   shouldBeA[TypeDouble] thatsIt
        its.opnd   shouldBe (my param "%p1")
        its.ty     shouldBeA[TypeDouble] thatsIt
      }
      my inst "%sitofp" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.SITOFP 
        its.fromTy shouldBeATypeIntOf 64
        its.toTy   shouldBeA[TypeDouble] thatsIt
        its.opnd   shouldBe (my param "%p1")
        its.ty     shouldBeA[TypeDouble] thatsIt
      }
      my inst "%bitcast0" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.BITCAST 
        its.fromTy shouldBeATypeIntOf 32
        its.toTy   shouldBeA[TypeFloat] thatsIt
        its.opnd   shouldBe (my param "%p0")
        its.ty     shouldBeA[TypeFloat] thatsIt
      }
      my inst "%bitcast1" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.BITCAST 
        its.fromTy shouldBeATypeIntOf 64
        its.toTy   shouldBeA[TypeDouble] thatsIt
        its.opnd   shouldBe (my param "%p1")
        its.ty     shouldBeA[TypeDouble] thatsIt
      }
      my inst "%bitcast2" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.BITCAST 
        its.fromTy shouldBeA[TypeFloat] thatsIt
        its.toTy   shouldBeATypeIntOf 32
        its.opnd   shouldBe (my param "%p2")
        its.ty     shouldBeATypeIntOf 32
      }
      my inst "%bitcast3" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.BITCAST 
        its.fromTy shouldBeA[TypeDouble] thatsIt
        its.toTy   shouldBeATypeIntOf 64
        its.opnd   shouldBe (my param "%p3")
        its.ty     shouldBeATypeIntOf 64
      }
    }
Kunshan Wang's avatar
Kunshan Wang committed
455

Kunshan Wang's avatar
Kunshan Wang committed
456 457 458 459 460 461 462 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 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 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 634 635 636 637 638 639 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 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
    in (our func "@refCastTest") { (func, cfg) =>
      val my = cfg
      
      my inst "%refcast" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.REFCAST
        its.fromTy shouldBeA[TypeRef] { _.ty shouldBeA[TypeVoid] thatsIt }
        its.toTy   shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf 32 }
        its.opnd   shouldBe (my param "%p0")
        its.ty     shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf 32 }
      }
      my inst "%irefcast" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.IREFCAST
        its.fromTy shouldBeA[TypeIRef] { _.ty shouldBeA[TypeVoid] thatsIt }
        its.toTy   shouldBeA[TypeIRef] { _.ty shouldBeATypeIntOf 64 }
        its.opnd   shouldBe (my param "%p1")
        its.ty     shouldBeA[TypeIRef] { _.ty shouldBeATypeIntOf 64 }
      }
      my inst "%funccast" shouldBeA[InstConv] { its => 
        its.op     shouldBe ConvOptr.FUNCCAST
        its.fromTy shouldBeA[TypeFunc] { _.sig shouldBeA[FuncSig] { its =>
          its.retTy shouldBeA[TypeVoid] thatsIt
          its.paramTy shouldBe empty
        }}
        its.toTy   shouldBeA[TypeFunc] { _.sig shouldBe (our sig "@iiisig") }
        its.opnd   shouldBe (my param "%p2")
        its.ty     shouldBeA[TypeFunc] { _.sig shouldBe (our sig "@iiisig") }
      }
    }
    
    in (our func "@ctrlFlow") { (func, cfg) =>
      val my = cfg
      
      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 =>
        its.opndTy shouldBeATypeIntOf 32
        its.opnd shouldBe (my inst "%phi")
        its.defDest shouldBe (my bb "%other")
        for ((c, b) <- its.cases) {
          c shouldBeA[ConstInt] { _.num.longValue match {
            case 1 => b shouldBe (my bb "%one")
            case 2 => b shouldBe (my bb "%two")
          }}
        }
      }
      
      my inst "%phi" shouldBeA[InstPhi] { its =>
        its.opndTy shouldBeATypeIntOf 32
        for ((b, c) <- its.cases) {
          if (b == (my bb "%entry")) { c shouldBeAConstIntOf(32, 0) }
          if (b == (my bb "%next")) { c shouldBe (my inst "%i2") }
        }
      }
      
      (my inst "%br1").ty    shouldBeA[TypeVoid] thatsIt
      (my inst "%br2").ty    shouldBeA[TypeVoid] thatsIt
      (my inst "%switch").ty shouldBeA[TypeVoid] thatsIt
      (my inst "%phi").ty    shouldBeATypeIntOf 32
    }
  
    in (our func "@caller1") { (func, cfg) =>
      val my = cfg
      
      my inst "%v1" shouldBeA[InstCall] { its =>
        its.sig.retTy shouldBeA[TypeVoid] thatsIt
        its.sig.paramTy shouldBe empty
        its.callee shouldBe (our globalValue "@callee1")
        its.args shouldBe empty
        its.ty shouldBeA[TypeVoid] thatsIt
      }
      
      my inst "%v2" shouldBeA[InstCall] { its =>
        its.sig shouldBe (our sig "@iiisig")
        its.callee shouldBe (our globalValue "@callee2")
        its.args(0) shouldBeAConstIntOf(64, 1)
        its.args(1) shouldBeAConstIntOf(64, 2)
        its.args.size shouldBe 2
        its.ty shouldBeATypeIntOf 64
      }
      
      my inst "%v4" shouldBeA[InstCall] { its =>
        its.sig.retTy shouldBeA[TypeVoid] thatsIt
        its.sig.paramTy shouldBe empty
        its.callee shouldBe (our globalValue "@callee1")
        its.args shouldBe empty
        its.keepAlives(0) shouldBe (my inst "%v2")
        its.keepAlives(1) shouldBe (my inst "%v3")
        its.keepAlives.size shouldBe 2
        its.ty shouldBeA[TypeVoid] thatsIt
      }
      
      my inst "%v3" shouldBeA[InstInvoke] { its =>
        its.sig shouldBe (our sig "@iiisig")
        its.callee shouldBe (our globalValue "@callee3")
        its.args(0) shouldBeAConstIntOf(64, 3)
        its.args(1) shouldBeAConstIntOf(64, 4)
        its.args.size shouldBe 2
        its.nor shouldBe (my bb "%cont")
        its.exc shouldBe (my bb "%catch")
        its.ty shouldBeATypeIntOf 64
      }      

      my inst "%v5" shouldBeA[InstInvoke] { its =>
        its.sig shouldBe (our sig "@iiisig")
        its.callee shouldBe (our globalValue "@callee3")
        its.args(0) shouldBe (my inst "%v3")
        its.args(1) shouldBe (my inst "%v3")
        its.args.size shouldBe 2
        its.nor shouldBe (my bb "%cont2")
        its.exc shouldBe (my bb "%catch")
        its.keepAlives(0) shouldBe (my inst "%v2")
        its.keepAlives.size shouldBe 1
        its.ty shouldBeATypeIntOf 64
      }  
      
      my inst "%retv" shouldBeA[InstRetVoid] { _.ty shouldBeA[TypeVoid] thatsIt }
      my inst "%exc" shouldBeA[InstLandingpad] { _.ty shouldBeA[TypeRef] {
        _.ty shouldBeA[TypeVoid] thatsIt
      }}
    }
    
    in (our func "@caller2") { (func, cfg) =>
      val my = cfg
      
      my inst "%tc" shouldBeA[InstTailCall] { its =>
        its.sig shouldBe (our sig "@iiisig")
        its.callee shouldBe (our globalValue "@callee2")
        its.args(0) shouldBe (my inst "%p0")
        its.args(1) shouldBe (my inst "%p1")
        its.args.size shouldBe 2
        its.ty shouldBeA[TypeVoid] thatsIt
      }
    }
 
    in (our func "@callee2") { (func, cfg) =>
      val my = cfg
      
      my inst "%ret" shouldBeA[InstRet] { its =>
        its.retTy shouldBeATypeIntOf 64
        its.retVal shouldBe (my inst "%rv")
        its.ty shouldBeA[TypeVoid] thatsIt
      }
    }     
   
 
    in (our func "@callee3") { (func, cfg) =>
      val my = cfg
      
      my inst "%throw" shouldBeA[InstThrow] { its =>
        its.excVal shouldBe (my inst "%exc")
        its.ty shouldBeA[TypeVoid] thatsIt
      }
    }
    
    in (our func "@aggregate") { (func, cfg) =>
      val my = cfg
      
      my inst "%e0" shouldBeA[InstExtractValue] { its =>
        its.strTy shouldBe (our ty "@sid")
        its.index shouldBe 0
        its.opnd shouldBe (our const "@sid1")
        its.ty shouldBeATypeIntOf 64
      }
      
      my inst "%e1" shouldBeA[InstExtractValue] { its =>
        its.strTy shouldBe (our ty "@sid")
        its.index shouldBe 1
        its.opnd shouldBe (our const "@sid1")
        its.ty shouldBeA[TypeDouble] thatsIt
      }
      
      my inst "%i0" shouldBeA[InstInsertValue] { its =>
        its.strTy shouldBe (our ty "@sid")
        its.index shouldBe 0
        its.opnd shouldBe (our const "@sid1")
        its.newVal shouldBeAConstIntOf(64, 40)
        its.ty shouldBe (our ty "@sid")
      }
      
      my inst "%i1" shouldBeA[InstInsertValue] { its =>
        its.strTy shouldBe (our ty "@sid")
        its.index shouldBe 1
        its.opnd shouldBe (our const "@sid1")
        its.newVal shouldBeAConstDoubleOf 40.0d
        its.ty shouldBe (our ty "@sid")
      }
    }
    
    in (our func "@memops") { (func, cfg) =>
      val my = cfg
      
      my inst "%new" shouldBeA[InstNew] { its =>
        its.allocTy shouldBeATypeIntOf 64
        its.ty shouldBeA[TypeRef] { _.ty shouldBeATypeIntOf 64 }
      }
      
      my inst "%newhybrid" shouldBeA[InstNewHybrid] { its =>
        its.allocTy shouldBe (our ty "@hic")
        its.length shouldBe (my param "%p0")
        its.ty shouldBeA[TypeRef] { _.ty shouldBe (our ty "@hic") }
      }
      
      my inst "%alloca" shouldBeA[InstAlloca] { its =>
        its.allocTy shouldBeATypeIntOf 64
        its.ty shouldBeA[TypeIRef] { _.ty shouldBeATypeIntOf 64 }
      }
      
      my inst "%allocahybrid" shouldBeA[InstAllocaHybrid] { its =>
        its.allocTy shouldBe (our ty "@hic")
        its.length shouldBe (my param "%p0")
        its.ty shouldBeA[TypeIRef] { _.ty shouldBe (our ty "@hic") }
      }

      my inst "%new2" shouldBeA[InstNew] { its =>
        its.allocTy shouldBe (our ty "@sid")
        its.ty shouldBeA[TypeRef] { _.ty shouldBe (our ty "@sid") }
      }
      
      my inst "%alloca2" shouldBeA[InstAlloca] { its =>
        its.allocTy shouldBe (our ty "@al")
        its.ty shouldBeA[TypeIRef] { _.ty shouldBe (our ty "@al") }
      }
      
      my inst "%getiref" shouldBeA[InstGetIRef] { its =>
        its.referentTy shouldBe (our ty "@sid")
        its.opnd shouldBe (my inst "%new2")
        its.ty shouldBeA[TypeIRef] { _.ty shouldBe (our ty "@sid") }
      }
Kunshan Wang's avatar
Kunshan Wang committed
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 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 782 783 784 785 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 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 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 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007
      
      my inst "%getfieldiref" shouldBeA[InstGetFieldIRef] { its =>
        its.referentTy shouldBe (our ty "@sid")
        its.index shouldBe 0
        its.opnd shouldBe (my inst "%getiref")
        its.ty shouldBeA[TypeIRef] { _.ty shouldBeATypeIntOf 64 }
      }
      
      my inst "%getelemiref" shouldBeA[InstGetElemIRef] { its =>
        its.referentTy shouldBe (our ty "@al")
        its.opnd shouldBe (my inst "%alloca2")
        its.index shouldBe (my param "%p1")
        its.ty shouldBeA[TypeIRef] { _.ty shouldBeATypeIntOf 64 }
      }
      
      my inst "%shiftiref" shouldBeA[InstShiftIRef] { its =>
        its.referentTy shouldBeATypeIntOf 8
        its.opnd shouldBe (my inst "%getvarpartiref")
        its.offset shouldBe (my param "%p1")
        its.ty shouldBeA[TypeIRef] { _.ty shouldBeATypeIntOf 8 }
      }

      my inst "%getfixedpartiref" shouldBeA[InstGetFixedPartIRef] { its =>
        its.referentTy shouldBe (our ty "@hic")
        its.opnd shouldBe (my inst "%allocahybrid")
        its.ty shouldBeA[TypeIRef] { _.ty shouldBeATypeIntOf 64 }
      }
      
      my inst "%getvarpartiref" shouldBeA[InstGetVarPartIRef] { its =>
        its.referentTy shouldBe (our ty "@hic")
        its.opnd shouldBe (my inst "%allocahybrid")
        its.ty shouldBeA[TypeIRef] { _.ty shouldBeATypeIntOf 8 }
      }
      
      my inst "%load" shouldBeA[InstLoad] { its =>
        its.ord shouldBe MemoryOrdering.NOT_ATOMIC
        its.referentTy shouldBeATypeIntOf 64
        its.loc shouldBe (my inst "%alloca")
        its.ty shouldBeATypeIntOf 64
      }
      
      my inst "%store" shouldBeA[InstStore] { its =>
        its.ord shouldBe MemoryOrdering.NOT_ATOMIC
        its.referentTy shouldBeATypeIntOf 64
        its.loc shouldBe (my inst "%alloca")
        its.newVal shouldBeAConstIntOf(64, 42)
        its.ty shouldBeA[TypeVoid] thatsIt
      }
      
      my inst "%cmpxchg" shouldBeA[InstCmpXchg] { its =>
        its.ordSucc shouldBe MemoryOrdering.ACQUIRE
        its.ordFail shouldBe MemoryOrdering.MONOTONIC
        its.referentTy shouldBeATypeIntOf 64
        its.loc shouldBe (my inst "%alloca")
        its.expected shouldBeAConstIntOf(64, 42)
        its.desired shouldBeAConstIntOf(64, 0)
        its.ty shouldBeATypeIntOf 64
      }
    
      my inst "%atomicrmw" shouldBeA[InstAtomicRMW] { its =>
        its.ord shouldBe MemoryOrdering.ACQ_REL
        its.op shouldBe AtomicRMWOptr.ADD
        its.referentTy shouldBeATypeIntOf 64
        its.loc shouldBe (my inst "%alloca")
        its.opnd shouldBeAConstIntOf(64, 50)
        its.ty shouldBeATypeIntOf 64
      }
   
      my inst "%fence" shouldBeA[InstFence] { its =>
        its.ord shouldBe (MemoryOrdering.MONOTONIC)
        its.ty shouldBeA[TypeVoid] thatsIt
      }
    }
    
    in (our func "@memorder") { (func, cfg) =>
      val my = cfg
      
      my inst "%l0" shouldBeA[InstLoad] { _.ord = MemoryOrdering.NOT_ATOMIC }
      my inst "%l1" shouldBeA[InstLoad] { _.ord = MemoryOrdering.UNORDERED }
      my inst "%l2" shouldBeA[InstLoad] { _.ord = MemoryOrdering.MONOTONIC }
      my inst "%f3" shouldBeA[InstFence] { _.ord = MemoryOrdering.ACQUIRE }
      my inst "%f4" shouldBeA[InstFence] { _.ord = MemoryOrdering.RELEASE }
      my inst "%f5" shouldBeA[InstFence] { _.ord = MemoryOrdering.ACQ_REL }
      my inst "%l6" shouldBeA[InstLoad] { _.ord = MemoryOrdering.SEQ_CST }
    }
    
    in (our func "@atomicrmwops") { (func, cfg) =>
      val my = cfg
      
      my inst "%old0" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.XCHG }
      my inst "%old1" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.ADD }
      my inst "%old2" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.SUB }
      my inst "%old3" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.AND }
      my inst "%old4" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.NAND }
      my inst "%old5" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.OR }
      my inst "%old6" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.XOR }
      my inst "%old7" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.MAX }
      my inst "%old8" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.MIN }
      my inst "%old9" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.UMAX }
      my inst "%olda" shouldBeA[InstAtomicRMW] { _.op = AtomicRMWOptr.UMIN }
    }
    
    
    in (our func "@traps") { (func, cfg) =>
      val my = cfg
      
      my inst "%tp" shouldBeA[InstTrap] { its =>
        its.retTy shouldBeATypeIntOf 32
        its.nor shouldBe (my bb "%trapcont")
        its.exc shouldBe (my bb "%trapexc")
        its.keepAlives shouldBe Seq(my inst "%b", my inst "%wp")
      }
      
      my inst "%wp" shouldBeA[InstWatchpoint] { its =>
        its.wpID shouldBe 1
        its.retTy shouldBeATypeIntOf 64
        its.dis shouldBe (my bb "%body")
        its.nor shouldBe (my bb "%wpcont")
        its.exc shouldBe (my bb "%wpexc")
        its.keepAlives shouldBe Seq(my inst "%a")
      }
    }
    
    in (our func "@ccall") { (func, cfg) =>
      val my = cfg
      
      my inst "%rv" shouldBeA[InstCCall] { its =>
        its.callConv shouldBe CallConv.DEFAULT
        its.sig.retTy shouldBeA[TypeVoid] thatsIt
        its.sig.paramTy(0) shouldBeA[TypeDouble] thatsIt
        its.sig.paramTy.size shouldBe 1
        its.callee shouldBe (my param "%p0")
        its.args.size shouldBe 1
        its.args(0) shouldBeAConstDoubleOf(3.14d)
      }
    }
    
    in (our func "@stack_and_intrinsic") { (func, cfg) =>
      val my = cfg
      
      my inst "%ns" shouldBeA[InstNewStack] { its =>
        its.sig shouldBe (our sig "@iiisig")
        its.callee shouldBe (our const "@callee2")
        its.args.size shouldBe 2
        its.args(0) shouldBeAConstIntOf(64, 5)
        its.args(1) shouldBeAConstIntOf(64, 6)
      }
      
      my inst "%i" shouldBeA[InstICall] { its =>
        its.iFunc shouldBe IFuncs.UVM_SWAP_STACK
        its.args.size shouldBe 1
        its.args(0) shouldBe (my inst "%ns")
        its.keepAlives.size shouldBe 1
        its.keepAlives(0) shouldBe (my inst "%b")
      }

      my inst "%j" shouldBeA[InstIInvoke] { its =>
        its.iFunc shouldBe IFuncs.UVM_KILL_STACK
        its.args.size shouldBe 1
        its.args(0) shouldBe (my inst "%ns")
        its.nor shouldBe (my bb "%nor")
        its.exc shouldBe (my bb "%exc")
        its.keepAlives.size shouldBe 2
        its.keepAlives(0) shouldBe (my inst "%b")
        its.keepAlives(1) shouldBe (my inst "%c")
      }
    }
    in (our func "@inference") { (func, cfg) =>
      val my = cfg

      my inst "%add" shouldBeA[InstBinOp] { its =>
        its.op1 shouldBeAConstIntOf(8, 41)
        its.op2 shouldBeAConstIntOf(8, 42)
      }
      my inst "%sub" shouldBeA[InstBinOp] { its =>
        its.op1 shouldBeAConstIntOf(16, 43)
        its.op2 shouldBeAConstIntOf(16, 44)
      }
      my inst "%mul" shouldBeA[InstBinOp] { its =>
        its.op1 shouldBeAConstIntOf(32, 45)
        its.op2 shouldBeAConstIntOf(32, 46)
      }
      my inst "%udiv" shouldBeA[InstBinOp] { its =>
        its.op1 shouldBeAConstIntOf(64, 47)
        its.op2 shouldBeAConstIntOf(64, 48)
      }
      my inst "%fadd" shouldBeA[InstBinOp] { its =>
        its.op1 shouldBeAConstFloatOf(49.0f)
        its.op2 shouldBeAConstFloatOf(50.0f)
      }
      my inst "%fsub" shouldBeA[InstBinOp] { its =>
        its.op1 shouldBeAConstDoubleOf(51.0d)
        its.op2 shouldBeAConstDoubleOf(52.0d)
      }
      
      my inst "%eq" shouldBeA[InstCmp] { its =>
        its.op1 shouldBeAConstIntOf(64, 53)
        its.op2 shouldBeAConstIntOf(64, 54)
      }
      my inst "%fueq" shouldBeA[InstCmp] { its =>
        its.op1 shouldBeAConstDoubleOf(55.0d)
        its.op2 shouldBeAConstDoubleOf(56.0d)
      }
      
      my inst "%trunc" shouldBeA[InstConv] { its =>
        its.opnd shouldBeAConstIntOf(64, 57)
      }
      my inst "%fptrunc" shouldBeA[InstConv] { its =>
        its.opnd shouldBeAConstDoubleOf(58.0d)
      }
      
      my inst "%refcast" shouldBeA[InstConv] { its =>
        its.opnd shouldBeA[ConstNull] { _.constTy shouldBeA[TypeRef] {
          _.ty shouldBeA[TypeVoid] thatsIt
        }}
      }
      my inst "%irefcast" shouldBeA[InstConv] { its =>
        its.opnd shouldBeA[ConstNull] { _.constTy shouldBeA[TypeIRef] {
          _.ty shouldBeA[TypeVoid] thatsIt
        }}
      }
      
      my inst "%select" shouldBeA[InstSelect] { its =>
        its.ifTrue shouldBeAConstDoubleOf(59.0d)
        its.ifFalse shouldBeAConstDoubleOf(60.0d)
      }
      
      my inst "%switch" shouldBeA[InstSwitch] { its =>
        its.opnd shouldBeAConstIntOf(32, 61)
        its.cases(0)._1 shouldBeAConstIntOf(32, 62)
      }
      
      my inst "%phi" shouldBeA[InstPhi] { its =>
        its.cases(0)._2 shouldBeAConstIntOf(32, 63)
      }
      
      my inst "%call" shouldBeA[InstCall] { its =>
        its.args(0) shouldBeAConstIntOf(8, 64)
        its.args(1) shouldBeAConstIntOf(16, 65)
        its.args(2) shouldBeAConstIntOf(32, 66)
        its.args(3) shouldBeAConstIntOf(64, 67)
        its.args(4) shouldBeAConstFloatOf(68.0f)
        its.args(5) shouldBeAConstDoubleOf(69.0d)
      }
      
      my inst "%invoke" shouldBeA[InstInvoke] { its =>
        its.args(0) shouldBeAConstIntOf(8, 70)
        its.args(1) shouldBeAConstIntOf(16, 71)
        its.args(2) shouldBeAConstIntOf(32, 72)
        its.args(3) shouldBeAConstIntOf(64, 73)
        its.args(4) shouldBeAConstFloatOf(74.0f)
        its.args(5) shouldBeAConstDoubleOf(75.0d)
      }
      
      my inst "%tailcall" shouldBeA[InstTailCall] { its =>
        its.args(0) shouldBeAConstIntOf(8, 76)
        its.args(1) shouldBeAConstIntOf(16, 77)
        its.args(2) shouldBeAConstIntOf(32, 78)
        its.args(3) shouldBeAConstIntOf(64, 79)
        its.args(4) shouldBeAConstFloatOf(80.0f)
        its.args(5) shouldBeAConstDoubleOf(81.0d)
      }
      
      my inst "%extractvalue" shouldBeA[InstExtractValue] { its =>
        its.opnd shouldBeA[ConstStruct] { s =>
          s.fields(0) shouldBeAConstIntOf(8, 82)
          s.fields(1) shouldBeAConstIntOf(16, 83)
          s.fields(2) shouldBeAConstIntOf(32, 84)
          s.fields(3) shouldBeAConstIntOf(64, 85)
          s.fields(4) shouldBeAConstFloatOf(86.0f)
          s.fields(5) shouldBeAConstDoubleOf(87.0d)
        }
      }
      
      my inst "%insertvalue" shouldBeA[InstInsertValue] { its =>
        its.opnd shouldBeA[ConstStruct] { s =>
          s.fields(0) shouldBeAConstIntOf(8, 88)
          s.fields(1) shouldBeAConstIntOf(16, 89)
          s.fields(2) shouldBeAConstIntOf(32, 90)
          s.fields(3) shouldBeAConstIntOf(64, 91)
          s.fields(4) shouldBeAConstFloatOf(92.0f)
          s.fields(5) shouldBeAConstDoubleOf(93.0d)
        }
        its.newVal shouldBeAConstIntOf(8, 94)
      }
      
      my inst "%store" shouldBeA[InstStore] { its =>
        its.newVal shouldBeAConstIntOf(32, 99)
      }
      my inst "%cmpxchg" shouldBeA[InstCmpXchg] { its =>
        its.expected shouldBeAConstIntOf(32, 100)
        its.desired shouldBeAConstIntOf(32, 101)
      }
      my inst "%atomicrmw" shouldBeA[InstAtomicRMW] { its =>
        its.opnd shouldBeAConstIntOf(32, 102)
      }
      
      my inst "%ccall" shouldBeA[InstCCall] { its =>
        its.args(0) shouldBeAConstIntOf(8, 103)
        its.args(1) shouldBeAConstIntOf(16, 104)
        its.args(2) shouldBeAConstIntOf(32, 105)
        its.args(3) shouldBeAConstIntOf(64, 106)
        its.args(4) shouldBeAConstFloatOf(107.0f)
        its.args(5) shouldBeAConstDoubleOf(108.0d)
      }
      
      my inst "%newstack" shouldBeA[InstNewStack] { its =>
        its.args(0) shouldBeAConstIntOf(8, 109)
        its.args(1) shouldBeAConstIntOf(16, 110)
        its.args(2) shouldBeAConstIntOf(32, 111)
        its.args(3) shouldBeAConstIntOf(64, 112)
        its.args(4) shouldBeAConstFloatOf(113.0f)
        its.args(5) shouldBeAConstDoubleOf(114.0d)
      }
Kunshan Wang's avatar
Kunshan Wang committed
1008
    }
Kunshan Wang's avatar
Kunshan Wang committed
1009
  }
Kunshan Wang's avatar
Kunshan Wang committed
1010
}