Commit 683bfb90 authored by Kunshan Wang's avatar Kunshan Wang

Use reference equality for Type and SSAVariable.

Scala defines a equals() function for case classes which uses structural
equality, but it is not desired in our case.
parent adc1a1ac
......@@ -6,6 +6,10 @@ import uvm.types._
abstract class SSAVariable extends IdentifiedSettable {
override def hashCode(): Int = id
override def equals(that: Any): Boolean = that match {
case v: AnyRef => this eq v
case _ => false
}
}
// Global variables: Constants, Global Cells and Functions (Function is defined in controlFlow.scala)
......
......@@ -4,6 +4,11 @@ import uvm._
abstract class Type extends IdentifiedSettable {
override final def toString: String = Type.prettyPrint(this)
override def hashCode(): Int = System.identityHashCode(this)
override def equals(that: Any): Boolean = that match {
case v: AnyRef => this eq v
case _ => false
}
}
abstract class FPType extends Type
......@@ -35,22 +40,22 @@ case class TypeVector(var elemTy: Type, var len: Long) extends AbstractSeqType
object Type {
def prettyPrint(ty: Type): String = ty match {
case TypeInt(length) => "int<%d>".format(length)
case TypeFloat() => "float"
case TypeDouble() => "double"
case TypeRef(ty) => "ref<%s>".format(ty.repr)
case TypeIRef(ty) => "iref<%s>".format(ty.repr)
case TypeWeakRef(ty) => "weakref<%s>".format(ty.repr)
case TypeStruct(fieldTy) => "struct<%s>".format(fieldTy.map(_.repr).mkString(" "))
case TypeArray(elemTy, len) => "array<%s %d>".format(elemTy.repr, len)
case TypeInt(length) => "int<%d>".format(length)
case TypeFloat() => "float"
case TypeDouble() => "double"
case TypeRef(ty) => "ref<%s>".format(ty.repr)
case TypeIRef(ty) => "iref<%s>".format(ty.repr)
case TypeWeakRef(ty) => "weakref<%s>".format(ty.repr)
case TypeStruct(fieldTy) => "struct<%s>".format(fieldTy.map(_.repr).mkString(" "))
case TypeArray(elemTy, len) => "array<%s %d>".format(elemTy.repr, len)
case TypeHybrid(fixedPart, varPart) => "hybrid<%s %s>".format(fixedPart.repr, varPart.repr)
case TypeVoid() => "void"
case TypeFunc(sig) => "func<%s>".format(FuncSig.prettyPrint(sig))
case TypeThread() => "thread"
case TypeStack() => "stack"
case TypeTagRef64() => "tagref64"
case TypeVector(elemTy, len) => "vector<%s %d>".format(elemTy.repr, len)
case _ => "unknown type " + ty.getClass.getName
case TypeVoid() => "void"
case TypeFunc(sig) => "func<%s>".format(FuncSig.prettyPrint(sig))
case TypeThread() => "thread"
case TypeStack() => "stack"
case TypeTagRef64() => "tagref64"
case TypeVector(elemTy, len) => "vector<%s %d>".format(elemTy.repr, len)
case _ => "unknown type " + ty.getClass.getName
}
}
......
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.mem.TypeSizes.Word
import ch.qos.logback.classic.Level._
import uvm.refimpl.UvmBundleTesterBase
import java.io.StringReader
class UvmInterpreterTestBigFunc extends UvmBundleTesterBase {
setLogLevels(
ROOT_LOGGER_NAME -> INFO,
"uvm.refimpl.itpr" -> DEBUG)
preloadBundles("tests/uvm-refimpl-test/extra-big-func.uir")
"The extra big function" should "execute properly" in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@big")
val hParam = ca.putInt("@i64", 0)
testFunc(ca, func, Seq(hParam)) { (ca, th, st, wp) =>
val Seq(i) = ca.dumpKeepalives(st, 0)
ca.toInt(i, true) shouldEqual 200
TrapRebindPassVoid(st)
}
ca.close()
}
"The Micro VM" should "sustain frequent bundle loading" in {
val ca = microVM.newClientAgent()
for(i <- 0 until 100) {
val miniBundle = s".global @h${i} <@i64>"
ca.loadBundle(new StringReader(miniBundle))
}
val sb = new StringBuilder()
sb ++= ".funcdef @bigger VERSION @bigger.v1 <@big.sig> (%p) {\n"
sb ++= " %entry:\n"
for(i <- 0 until 100) {
sb ++= s" %r${i} = STORE <@i64> @h${i} %p\n"
}
// sb ++= " TRAP <@void>\n"
sb ++= " COMMINST @uvm.thread_exit\n"
sb ++= "}"
ca.loadBundle(new StringReader(sb.toString()))
val func = ca.putFunction("@bigger")
val hParam = ca.putInt("@i64", 42)
testFunc(ca, func, Seq(hParam)) { (ca, th, st, wp) =>
val hr = ca.putGlobal("@h12")
val hv = ca.load(MemoryOrder.NOT_ATOMIC, hr)
val v = ca.toInt(hv, true).toInt
v shouldEqual 42
TrapRebindPassVoid(st)
}
ca.close()
}
}
\ No newline at end of file
package uvm.refimpl.misc
import org.scalatest._
import java.io.FileReader
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.refimpl._
import uvm.refimpl.itpr._
import uvm.ssavariables.MemoryOrder._
import uvm.ssavariables.AtomicRMWOptr._
import uvm.refimpl.mem.TypeSizes.Word
import com.typesafe.scalalogging.Logger
import org.slf4j.LoggerFactory
import ch.qos.logback.classic.{ Logger => LLogger }
import ch.qos.logback.classic.Level
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.HashMap
class HashableSSAValueTest extends FlatSpec with Matchers {
"HashMap" should "be able to hold many items" in {
val hm = new HashMap[Int, Int]()
for (i <- 0 until 100) {
val maybeOld = hm.put(i, i)
maybeOld match {
case None =>
case Some(old) => {
println("%d conflicts with %d".format(i, old))
}
}
}
}
"GlobalCell" should "be hashable" in {
val int64Ty = TypeInt(64)
int64Ty.id = 65536
int64Ty.name = Some("@i64")
val buf = new ArrayBuffer[GlobalCell]()
var nextID = 65537
for (i <- 0 until 100) {
val myID = nextID
nextID += 1
val gc = GlobalCell(int64Ty)
gc.id = myID
gc.name = Some("@g" + i)
buf += gc
}
val hm = new HashMap[GlobalCell, GlobalCell]()
for (gc <- buf) {
println("hashCode of gc %s is %d".format(gc.repr, gc.hashCode()))
val maybeOldGC = hm.put(gc, gc)
if (!maybeOldGC.isEmpty) {
val oldGC = maybeOldGC.get
println("gc %s got oldgc %s".format(gc.repr, oldGC.repr))
val equ = gc equals oldGC
println("Equal? %s".format(equ))
}
}
for (gc <- buf) {
if (!hm.contains(gc)) {
println("GlobalCell %s not contained!".format(gc.repr))
fail
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment