MuCtxIRBuilderPart.scala 1.11 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1 2 3 4
package uvm.refimpl

import uvm._
import uvm.refimpl.itpr._
5
import uvm.ir.irbuilder._
Kunshan Wang's avatar
Kunshan Wang committed
6 7 8 9 10 11 12 13 14 15

/**
 * Mix-in to MuCtx to support the IR building API.
 */
trait MuCtxIRBuilderPart {
  protected def microVM: MicroVM
  
  protected def addHandle[T <: MuValue](h: T): T

  @inline
16 17 18 19 20 21 22
  private def IRNODEREF = InternalTypes.IRNODEREF
  
  private def irBuilder = microVM.irBuilder
  
  private def makeConcreteMuIRNode(node: IRNode): MuIRNode = {
    ???
  }
Kunshan Wang's avatar
Kunshan Wang committed
23 24
  
  def newBundle(): MuBundleNode = {
25
    val node = irBuilder.newBundle()
Kunshan Wang's avatar
Kunshan Wang committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39
    addHandle(MuBundleNode(IRNODEREF, BoxIRNode(Some(node))))
  }

  def loadBundleFromNode(b: MuBundleNode): Unit = {
    require(!b.isNull, "bundle must not be NULL")
    val bundle = b.bundle
    microVM.addBundle(bundle)
  }
  
  def abortBundleNode(b: MuBundleNode): Unit = {
    // no op
  }
  
  def getNode(b: MuBundleNode, id: Int): MuIRNode = {
40 41 42
    require(!b.isNull, "bundle must not be NULL")
    val node = irBuilder.getNode(b.vb.node.get.asInstanceOf[BundleNode], id)
    addHandle(makeConcreteMuIRNode(node))
Kunshan Wang's avatar
Kunshan Wang committed
43 44 45 46 47 48 49
  }
  
  def getID(node: MuChildNode): Int = {
    require(!node.isNull)
    node.obj.id
  }
}