UvmInterpreterIRBuilderTests.scala 2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
package uvm.refimpl.itpr

import org.scalatest._
import java.io.FileReader
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.refimpl._
import uvm.refimpl.itpr._
import MemoryOrder._
import AtomicRMWOptr._
import uvm.refimpl.Word
import ch.qos.logback.classic.Level._
import uvm.refimpl.UvmBundleTesterBase
import uvm.refimpl.TrapHandlerResult.{ ThreadExit, Rebind }
import uvm.refimpl.HowToResume.{ PassValues, ThrowExc }
import uvm.ir.irbuilder.IRBuilder
import uvm.ir.textinput.ExtraMatchers

class UvmInterpreterIRBuilderTests extends UvmBundleTesterBase with ExtraMatchers {
  setLogLevels(
    ROOT_LOGGER_NAME -> INFO,
    "uvm.refimpl.itpr" -> DEBUG)

  preloadBundles("tests/uvm-refimpl-test/primitives.uir",
    "tests/uvm-refimpl-test/irbuilder-tests.uir")
Kunshan Wang's avatar
Kunshan Wang committed
27
  preloadHails("tests/uvm-refimpl-test/irbuilder-tests.hail")
28

29
  // Dump bundles to see run-time-loaded bundles
Kunshan Wang's avatar
Kunshan Wang committed
30
  override def makeMicroVM = MicroVM(new VMConf(sourceInfo=true, dumpBundle=true))
31

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
  "The new_ir_builder COMMINST" should "create an IR builder" in {
    val ctx = microVM.newContext()

    val func = ctx.handleFromFunc("@irbuilder_test")

    testFunc(ctx, func, Seq()) { (ctx, th, st, wp) =>
      val trapName = nameOf(ctx.curInst(st, 0))

      trapName match {
        case "@irbuilder_test.v1.entry.trap" => {
          val Seq(irb: MuOpaqueRefValue[IRBuilder], id1: MuIntValue) = ctx.dumpKeepalives(st, 0)

          irb.vb.obj.get shouldBeA[IRBuilder] thatsIt
          (id1.asInt32 >= 65536) shouldBe true

          returnFromTrap(st)
        }
49
        case "@irbuilder_test.v1.entry.trap2" => {
Kunshan Wang's avatar
Kunshan Wang committed
50
          val Seq(mySecondConstByID: MuIntValue, id2: MuIntValue) = ctx.dumpKeepalives(st, 0)
51 52
          
          mySecondConstByID.asInt32 shouldBe 50
Kunshan Wang's avatar
Kunshan Wang committed
53 54 55 56
          
          val id2_i32 = id2.asInt32.toInt
          val myname = microVM.nameOf(id2_i32)
          myname shouldEqual "@irbuilder_test.hello"
57 58 59

          returnFromTrap(st)
        }
60 61 62 63 64 65 66
        case _ => fail("Should not hit " + trapName)
      }
    }

    ctx.closeContext()
  }
}