internals.scala 1.33 KB
Newer Older
1 2 3 4 5 6
package uvm.refimpl

import uvm.types._
import uvm.ir.textinput.IDFactory
import scala.collection.mutable.HashMap
import uvm.FuncSig
Kunshan Wang's avatar
Kunshan Wang committed
7
import uvm.IdentifiedSettable
8 9 10 11

object InternalIDFactory extends IDFactory(32768) // IDs from 32768-65535 are for implementation internal use.

object InternalTypes {
Kunshan Wang's avatar
Kunshan Wang committed
12 13 14 15 16 17 18
  private implicit class IdentifiedSettableAssignable[T <: IdentifiedSettable](i: T) {
    def :=(name: String): T = {
      i.id = InternalIDFactory.getID()
      i.name = Some(name)
      i
    }
  }
19

Kunshan Wang's avatar
Kunshan Wang committed
20
  def internal(name: String) = "@uvm.internal.types." + name
21

Kunshan Wang's avatar
Kunshan Wang committed
22 23 24 25 26 27 28 29 30 31
  val VOID = TypeVoid() := internal("void")
  val BYTE = TypeInt(8) := internal("byte")
  val BYTE_ARRAY = TypeHybrid(VOID, BYTE) := internal("byte_array")

  val DOUBLE = TypeDouble() := internal("double")
  val I52 = TypeInt(52) := internal("i52")
  val REF_VOID = TypeRef(VOID) := internal("ref_void")
  val I6 = TypeInt(6) := internal("i6")

  val TAGREF64 = TypeTagRef64() := internal("tagref64")
32 33 34
}

object InternalTypePool {
Kunshan Wang's avatar
Kunshan Wang committed
35 36 37 38 39 40 41 42 43 44
  class LazyPool[FromT, ToT](factory: FromT => ToT) {
    val pool = HashMap[FromT, ToT]()
    def apply(obj: FromT): ToT = pool.get(obj).getOrElse(factory(obj))
  }
  object LazyPool {
    def apply[FromT, ToT](factory: FromT => ToT): LazyPool[FromT, ToT] = new LazyPool[FromT, ToT](factory)
  }

  val irefOf = LazyPool(TypeIRef)
  val funcOf = LazyPool(TypeFunc)
45
}