Commit 08b6e8f0 authored by Kunshan Wang's avatar Kunshan Wang

Scala 2.12.2, deprecated, clientsupport

Switched Scala version to 2.12.2, the most recent stable version.  It
will now require Java 1.8.

Fixed existing uses of deprecated features.

Removed the `uvm.clientsupport` package.  This package was intended to
help Mu clients build text-based Mu IR bundles.  However, we started
using the IR Builder API instead, and the `uvm.clientsupport` package
remained unused.  The same capability can be provided by the
`mu-tool-compiler` project
(https://gitlab.anu.edu.au/mu/mu-tool-compiler).  `uvm.clientsupport`
provided a non-SSA-to-ssa converter, which can be useful for clients.
If there are needs of resurrecting that feature, please checkout the
previous commit.
parent 9fcd3c14
......@@ -17,12 +17,12 @@ Specification](https://gitlab.anu.edu.au/mu/mu-spec).
* Install JDK 8. If you use Mac, download from
[Oracle](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html).
* If you use Mac, install [Homebrew](http://brew.sh/).
* Install [Scala](http://scala-lang.org/) 2.11. If you use Mac and Homebrew,
* Install [Scala](http://scala-lang.org/) 2.12. If you use Mac and Homebrew,
`brew install scala`.
* Install [sbt](http://www.scala-sbt.org/) 0.13. If you use Mac and Homebrew,
`brew install sbt`.
* Install [Scala IDE](http://scala-ide.org/) 4.x (Eclipse with pre-installed
plugins for Scala).
* Install [Scala IDE](http://scala-ide.org/) 4.6 or later (Eclipse with
pre-installed plugins for Scala).
* Clone this repository:
```bash
......@@ -49,7 +49,7 @@ sbt update genSrc eclipse
The reference implementation is developed and tested with Java VM 8. You need a
JRE to build the Scala/Java part, and a JDK to build the C binding.
You also need [Scala](http://scala-lang.org/) 2.11 and
You also need [Scala](http://scala-lang.org/) 2.12 and
[sbt](http://www.scala-sbt.org/) 0.13. It is recommended to install them using
the package manager of your operating system or distribution (such as apt-get,
yum, pacman, etc. for GNU/Linux distributions and Homebrew for Mac OS X) if such
......@@ -69,7 +69,7 @@ compile this project. Or you can do it step by step:
update`.
* To generate the Mu IR parser from the Antlr grammar, invoke `sbt genSrc`. The
generated sources will be in the `target/scala-2.11/src_managed` directory.
generated sources will be in the `target/scala-2.12/src_managed` directory.
* To compile, invoke `sbt compile`. This will also generate the Mu IR parser
using Antlr.
......
......@@ -17,19 +17,21 @@ lazy val root = (project in file(".")).
licenses := Seq("CC BY-SA 4.0" -> url("https://creativecommons.org/licenses/by-sa/4.0/legalcode")),
scalaVersion := "2.11.11",
scalaVersion := "2.12.2",
libraryDependencies ++= Seq(
"org.antlr" % "antlr4" % "4.7",
"com.typesafe.scala-logging" %% "scala-logging" % "3.5.0",
"com.typesafe.scala-logging" %% "scala-logging" % "3.7.1",
"ch.qos.logback" % "logback-classic" % "1.2.3",
"com.github.jnr" % "jnr-ffi" % "2.1.5",
"com.github.jnr" % "jffi" % "1.2.15" classifier "native",
"com.github.jnr" % "jnr-ffi" % "2.1.6",
"com.github.jnr" % "jffi" % "1.2.16" classifier "native",
"com.github.jnr" % "jnr-posix" % "3.0.41",
"org.scalatest" %% "scalatest" % "3.0.3" % "test",
"junit" % "junit" % "4.12" % "test"
),
scalacOptions += "-language:implicitConversions",
testOptions in Test += Tests.Argument("-oF"), // print full stack trace when testing
parallelExecution in Test := false, // disable parallel tests because the refimpl2 is not thread-safe
......
package uvm.clientsupport.text
import java.util
import scala.collection.JavaConversions._
/**
* A Mu IR bundle. This class is more representation-oriented rather than semantic oriented. For example, there are
* "type definitions" rather than "types". Similarly "function definitions" and "function declarations" are separated
* rather than contained in each other.
*/
class Bundle(
cTypeDefs: TraversableOnce[(TypeName, TypeCtor)],
cFuncSigDefs: TraversableOnce[(FuncSigName, FuncSig)],
cConstDefs: TraversableOnce[(GlobalVarName, Const)],
cGlobalCellDefs: TraversableOnce[(GlobalVarName, TypeName)],
cFuncDecls: TraversableOnce[(GlobalVarName, FuncSigName)],
cFuncVers: TraversableOnce[(FuncVerName, PostFuncVer)],
cFuncExpDefs: TraversableOnce[(GlobalVarName, Expose)],
cComments: TraversableOnce[(GlobalName, String)]
) {
private def buildMap[K, V](seq: TraversableOnce[(K, V)]): util.Map[K, V] = {
val map = new util.LinkedHashMap[K, V]
seq foreach { case (k, v) => map.put(k, v) }
map
}
lazy val typeDefs = buildMap(cTypeDefs)
lazy val funcSigDefs = buildMap(cFuncSigDefs)
lazy val constDefs = buildMap(cConstDefs)
lazy val globalCellDefs = buildMap(cGlobalCellDefs)
lazy val funcDecls = buildMap(cFuncDecls)
lazy val funcVers = buildMap(cFuncVers)
lazy val funcExpDefs = buildMap(cFuncExpDefs)
lazy val comments = buildMap(cComments)
override lazy val toString = {
val sb = new StringBuilder
def printBlock[N <: GlobalName, V](block: util.Map[N, V])(fn: (N, V) => Unit): Unit =
if (!block.isEmpty) {
sb append "\n"
block foreach { case (name, value) =>
Option(comments get name) foreach (_ split '\n' map ("// " + _ + "\n") foreach sb.append)
fn(name, value)
}
}
printBlock(typeDefs)((name, ctor) => sb append s".typedef $name = $ctor\n")
printBlock(funcSigDefs)((name, sig) => sb append s".funcsig $name = $sig\n")
printBlock(constDefs)((name, const) => sb append s".const $name <${const.ty}> = $const\n")
printBlock(globalCellDefs)((name, ty) => sb append s".global $name <$ty>\n")
printBlock(funcDecls)((name, sig) => sb append s".funcdecl $name <$sig>\n")
printBlock(funcExpDefs)((name, exp) => sb append s".expose $name = $exp\n")
printBlock(funcVers)((name, ver) =>
sb append s".funcdef ${ver.func} VERSION $name <${ver.sig}> $ver\n\n")
sb.toString
}
}
package uvm.clientsupport.text
import java.util
import scala.collection.JavaConversions
class IList[T](members: TraversableOnce[T]) extends util.AbstractList[T] with Traversable[T] {
def this(membersIterable: java.lang.Iterable[T]) =
this(JavaConversions iterableAsScalaIterable membersIterable)
private val vector = members.toVector
override def get(index: Int): T = vector(index)
override def size: Int = vector.length
override def isEmpty: Boolean = vector.isEmpty
override def toString = vector mkString " "
override def foreach[U](f: (T) => U): Unit = vector foreach f
def apply(idx: Int): T = vector(idx)
}
object IList {
def apply[T](members: T*): IList[T] = new IList(members)
def empty[T]: IList[T] = new IList[T](Nil)
}
This diff is collapsed.
This diff is collapsed.
package uvm.clientsupport.text
sealed abstract class TypeCtor(str: => String) {
override lazy val toString: String = str
}
object TypeCtor {
def Void = Singletons.Void; type Void = Singletons.Void.type
case class Int(bits: scala.Int) extends TypeCtor(s"int<$bits>")
def Float = Singletons.Float; type Float = Singletons.Float.type
def Double = Singletons.Double; type Double = Singletons.Double.type
def ThreadRef = Singletons.ThreadRef; type ThreadRef = Singletons.ThreadRef.type
def StackRef = Singletons.StackRef; type StackRef = Singletons.StackRef.type
def FrameCursorRef = Singletons.FrameCursorRef; type FrameCursorRef = Singletons.FrameCursorRef.type
case class Ref(ty: TypeCtor) extends TypeCtor(s"ref<$ty>")
case class IRef(ty: TypeCtor) extends TypeCtor(s"iref<$ty>")
case class WeakRef(ty: TypeCtor) extends TypeCtor(s"weakref<$ty>")
case class FuncRef(sig: FuncSigName) extends TypeCtor(s"funcref<$sig>")
case class UPtr(ty: TypeCtor) extends TypeCtor(s"uptr<$ty>")
case class UFuncPtr(sig: FuncSigName) extends TypeCtor(s"ufuncptr<$sig>")
def TagRef64 = Singletons.TagRef64; type TagRef64 = Singletons.TagRef64.type
case class Array(ty: TypeCtor, len: scala.Long) extends TypeCtor(s"array<$ty $len>")
case class Vector(ty: TypeCtor, len: scala.Int) extends TypeCtor(s"vector<$ty $len>")
case class Hybrid(fixedTy: TypeCtor, varTy: TypeCtor) extends TypeCtor(s"hybrid<$fixedTy $varTy>")
case class Struct(types: IList[TypeCtor]) extends TypeCtor(s"struct<${types mkString " "}>")
object Singletons {
case object Void extends TypeCtor("void")
case object Float extends TypeCtor("float")
case object Double extends TypeCtor("double")
case object ThreadRef extends TypeCtor("threadref")
case object StackRef extends TypeCtor("stackref")
case object FrameCursorRef extends TypeCtor("framecursorref")
case object TagRef64 extends TypeCtor("tagref64")
}
}
sealed trait MuName {
def name: String
}
sealed trait GlobalName extends MuName {
override lazy val toString = "@" + name
}
sealed trait LocalName extends MuName {
override lazy val toString = "%" + name
}
sealed trait VarName extends MuName
case class TypeName(name: String) extends TypeCtor("@" + name) with GlobalName
case class FuncSigName(name: String) extends GlobalName
case class FuncVerName(name: String) extends GlobalName
case class GlobalVarName(name: String) extends GlobalName with VarName
case class LocalVarName(name: String) extends LocalName with VarName
case class LabelName(name: String) extends LocalName
final class Flag(cName: String) {
val name = cName.toUpperCase.replaceAll("[^A-Z_]", "")
override def toString = "#" + name
}
package uvm.clientsupport.text
sealed abstract class Const(str: => String) {
def ty: TypeName
override def toString = str
}
object Const {
case class Null(ty: TypeName) extends Const("NULL")
case class Int(ty: TypeName, value: scala.Long) extends Const(value.toString)
case class Float(ty: TypeName, value: scala.Float)
extends Const(s"bitsf(0x${Integer.toHexString(java.lang.Float.floatToRawIntBits(value))})")
case class Double(ty: TypeName, value: scala.Double)
extends Const(s"bitsd(0x${java.lang.Long.toHexString(java.lang.Double.doubleToRawLongBits(value))})")
case class Pointer(ty: TypeName, addr: scala.Long) extends Const(addr.toString)
case class List(ty: TypeName, fields: IList[GlobalVarName]) extends Const(s"{$fields}")
}
case class FuncSig(paramTy: IList[TypeName], retTy: IList[TypeName]) {
override def toString = s"($paramTy) -> ($retTy)"
}
case class PreFuncVer(
func: GlobalVarName,
sig: FuncSigName,
params: IList[LocalVarName],
bbs: IList[PreBasicBlock]
) {
override lazy val toString = "(" + params + ") {\n" + (bbs mkString "\n") + "\n}"
}
case class PostFuncVer(func: GlobalVarName, sig: FuncSigName, bbs: IList[PostBasicBlock]) {
override lazy val toString = "{\n" + (bbs mkString "\n") + "\n}"
}
case class Expose(func: GlobalVarName, callConv: Flag, cookie: GlobalVarName) {
override def toString = s"$func $callConv $cookie"
}
trait Context {
def resolve(typeName: TypeName): Option[TypeCtor]
def resolve(funcSigName: FuncSigName): Option[FuncSig]
def typeDef(ctor: TypeCtor): TypeName
def funcSig(args: IList[TypeName], ret: IList[TypeName]): FuncSigName
def constDef(c: Const): GlobalVarName
}
\ No newline at end of file
package uvm.ir.irbuilder
import scala.collection.mutable.ArrayBuffer
import uvm._
import uvm.ir.irbuilder.IRBuilderNode._
import uvm.ssavariables._
import uvm.types._
import uvm.utils.Later
import uvm.utils.Later._
import uvm.ir.irbuilder.IRBuilderNode._
import scala.collection.mutable.ArrayBuffer
/** This class converts the soup of ID-referenced nodes into the refimpl's internal AST. */
class BundleConstructor(idNameMap: Map[MuID, MuName], nodeList: Seq[IRBuilderNode], globalBundle: GlobalBundle) {
......
package uvm.ir.textinput
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.collection.mutable.ArrayBuffer
import org.antlr.v4.runtime._
......@@ -41,11 +41,11 @@ class UIRTextReader(val defaultIDFactory: IDFactory, val recordSourceInfo: Boole
def read(ir: String, globalBundle: GlobalBundle, idFactory : IDFactory): TrantientBundle = {
logger.debug("Creating ANTLRInputStream...")
val input = new ANTLRInputStream(ir)
val input = CharStreams.fromString(ir)
read(ir, input, globalBundle, idFactory)
}
def parse(source: String, ais: ANTLRInputStream): IrContext = {
def parse(source: String, ais: CharStream): IrContext = {
logger.debug("Creating AccumulativeAntlrErrorListener...")
val ea = new AccumulativeAntlrErrorListener(source)
......@@ -67,11 +67,11 @@ class UIRTextReader(val defaultIDFactory: IDFactory, val recordSourceInfo: Boole
ast
}
def read(source: String, ais: ANTLRInputStream, globalBundle: GlobalBundle): TrantientBundle = {
def read(source: String, ais: CharStream, globalBundle: GlobalBundle): TrantientBundle = {
read(source, ais, globalBundle, defaultIDFactory)
}
def read(source: String, ais: ANTLRInputStream, globalBundle: GlobalBundle, idFactory: IDFactory): TrantientBundle = {
def read(source: String, ais: CharStream, globalBundle: GlobalBundle, idFactory: IDFactory): TrantientBundle = {
val ast = parse(source, ais)
logger.debug("Antlr parsed. Reading UIR AST into a Bundle...")
val instanceReader = new InstanceUIRTextReader(idFactory, source, ast, globalBundle, recordSourceInfo)
......@@ -118,11 +118,11 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
def resFuncByName(name: String): Function = cascadeLookup(name, bundle.funcNs, globalBundle.funcNs)
implicit def convFlag(f: FlagContext): Flag = Flag(f.FLAG().getText)
implicit def convFlagList(a: FlagListContext): Seq[Flag] = a.flag().map(convFlag)
implicit def convFlagList(a: FlagListContext): Seq[Flag] = a.flag().asScala.map(convFlag)
// Resolve global entities from special structures.
implicit def resTypeList(a: TypeListContext): Seq[Type] = a.`type`.map(resTy)
implicit def resFuncSigList(a: FuncSigListContext): Seq[FuncSig] = a.funcSig().map(resSig)
implicit def resTypeList(a: TypeListContext): Seq[Type] = a.`type`.asScala.map(resTy)
implicit def resFuncSigList(a: FuncSigListContext): Seq[FuncSig] = a.funcSig().asScala.map(resSig)
// Resolve special structures
......@@ -189,8 +189,8 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
case t: TypeDoubleContext => TypeDouble()
case t: TypeUPtrContext => TypeUPtr(null).later(phase1) { _.ty = t.ty }
case t: TypeUFuncPtrContext => TypeUFuncPtr(null).later(phase1) { _.sig = t.funcSig }
case t: TypeStructContext => TypeStruct(null).later(phase1) { _.fieldTys = t.fieldTys.map(resTy) }
case t: TypeHybridContext => TypeHybrid(null, null).later(phase1) { tt => tt.fieldTys = t.fieldTys.map(resTy); tt.varTy = t.varTy }
case t: TypeStructContext => TypeStruct(null).later(phase1) { _.fieldTys = t.fieldTys.asScala.map(resTy) }
case t: TypeHybridContext => TypeHybrid(null, null).later(phase1) { tt => tt.fieldTys = t.fieldTys.asScala.map(resTy); tt.varTy = t.varTy }
case t: TypeArrayContext => TypeArray(null, t.length.longValue()).later(phase1) { _.elemTy = t.ty }
case t: TypeVectorContext => TypeVector(null, t.length.longValue()).later(phase1) { _.elemTy = t.ty }
case t: TypeVoidContext => TypeVoid()
......@@ -209,14 +209,14 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
def mkSig(fsc: FuncSigConstructorContext): FuncSig = {
val sig = FuncSig(null, null).later(phase1) { sig =>
sig.retTys = for (t <- fsc.retTys) yield resTy(t)
sig.paramTys = for (t <- fsc.paramTys) yield resTy(t)
sig.retTys = for (t <- fsc.retTys.asScala) yield resTy(t)
sig.paramTys = for (t <- fsc.paramTys.asScala) yield resTy(t)
}
return sig
}
logger.debug("Reading types and sigs...")
ir.topLevelDef.map(_.getChild(0)).foreach {
ir.topLevelDef.asScala.map(_.getChild(0)).foreach {
case td: TypeDefContext => {
val ty = mkType(td.typeConstructor)
val name = td.nam
......@@ -246,7 +246,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
case cc: CtorFloatContext => ConstFloat(t, cc.floatLiteral)
case cc: CtorDoubleContext => ConstDouble(t, cc.doubleLiteral)
case cc: CtorListContext => ConstSeq(t, null).later(phase2) {
_.elems = for (gn <- cc.globalVar()) yield resGlobalVar(gn)
_.elems = for (gn <- cc.globalVar().asScala) yield resGlobalVar(gn)
}
case _: CtorNullContext => ConstNull(t)
case cc: CtorExternContext => ConstExtern(t, cc.symbol)
......@@ -287,7 +287,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
logger.debug("Reading consts, globals, funcdefs, funcdecls and expfuncs...")
val funcDefs = new ArrayBuffer[(Function, FuncDefContext)]
ir.topLevelDef().map(_.getChild(0)).foreach {
ir.topLevelDef().iterator.asScala.map(_.getChild(0)).foreach {
case cdctx: ConstDefContext => {
val ty = resTy(cdctx.ty)
val con = mkConst(ty, cdctx.constConstructor)
......@@ -385,7 +385,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
param
}
bb.norParams = label.bbParam.map { p =>
bb.norParams = label.bbParam.asScala.map { p =>
val param = mkNorParam(p.`type`(), p.name())
val sourceInfo = toSourceInfo(p)
addLocalVar(param, sourceInfo)
......@@ -418,9 +418,9 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
}
}
implicit def resArgList(a: ArgListContext): Seq[SSAVariable] = a.value.map(resVar)
implicit def resArgList(a: ArgListContext): Seq[SSAVariable] = a.value.asScala.map(resVar)
implicit def resKA(ka: KeepaliveClauseContext): Seq[LocalVariable] = ka.value.map(resLocalVar)
implicit def resKA(ka: KeepaliveClauseContext): Seq[LocalVariable] = ka.value.asScala.map(resLocalVar)
def resFuncCallBody(fcb: FuncCallBodyContext): (FuncSig, SSAVariable, Seq[SSAVariable]) =
(fcb.funcSig, fcb.callee, fcb.argList)
......@@ -463,7 +463,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
return 0
}
var status = 0
val texts = flagList.flag().map(_.getText)
val texts = flagList.flag().asScala.map(_.getText)
val ordered = Seq("#N", "#Z", "#C", "#V").filter(t => texts.contains(t))
if(ordered != texts ) {
......@@ -515,7 +515,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
case ii: InstSwitchContext =>
InstSwitch(ii.`type`, null, null, null).later(phase4) { i =>
i.opnd = ii.opnd; i.defDest = ii.defDest
i.cases = (for ((v, d) <- ii.caseVal.zip(ii.caseDest)) yield (resConst(v), resDestClause(d))).to[ArrayBuffer]
i.cases = (for ((v, d) <- (ii.caseVal.asScala zip ii.caseDest.asScala)) yield (resConst(v), resDestClause(d))).to[ArrayBuffer]
}
case ii: InstCallContext =>
InstCall(null, null, null, null, null).later(phase4) { i =>
......@@ -528,7 +528,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
}
case ii: InstRetContext =>
InstRet(ver, null).later(phase4) { i =>
i.retVals = ii.retVals.vals.map(resVar)
i.retVals = ii.retVals.vals.asScala.map(resVar)
}
case ii: InstThrowContext =>
InstThrow(null).later(phase4) { i =>
......@@ -663,7 +663,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
val instRess: ArrayBuffer[InstResult] = Option(instDef.instResults) match {
case None => ArrayBuffer()
case Some(r) => (for ((instResDef, index) <- r.results.zipWithIndex) yield {
case Some(r) => (for ((instResDef, index) <- r.results.asScala.zipWithIndex) yield {
val resName = globalize(instResDef.getText, bbName)
val instRes = InstResult(inst, index)
......@@ -681,12 +681,12 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
return inst
}
bb.insts = bbCtx.inst.map(i => mkInst(bb, i)).to[ArrayBuffer]
bb.insts = bbCtx.inst.asScala.map(i => mkInst(bb, i)).to[ArrayBuffer]
return bb
}
val bbs = fDefCtx.funcBody.basicBlock().map(makeBB).to[ArrayBuffer]
val bbs = fDefCtx.funcBody.basicBlock().asScala.map(makeBB).to[ArrayBuffer]
ver.bbs = bbs
......
......@@ -152,11 +152,11 @@ object VMConf {
val ReConf = """^\s*(\w+)=(\S+)\s*$""".r
def apply(confStr: String): VMConf = {
val kvs = confStr.lines map {
val kvs = confStr.lines.map {
case ReComment() => None
case ReBlank() => None
case ReConf(key, value) => Some((key, value))
} flatten
}.flatten
val map = kvs.toMap
......
......@@ -39,7 +39,7 @@ class TransitiveClosure[T](initialElems: Seq[T]) {
}
}
def +=(elem: T): TransitiveClosure[T] = { maybeEnqueue(elem); this }
def ++=(elems: Seq[T]): TransitiveClosure[T] = { elems.foreach(this +=); this }
def ++=(elems: Seq[T]): TransitiveClosure[T] = { elems.foreach(e => this += e); this }
}
object TransitiveClosureBuilder {
......@@ -381,7 +381,7 @@ class TransitiveClosureBuilder(initialSet: Seq[TopLevel], val primordial: Primor
}
override def visitFuncRefField(objRef: Word, iRef: Word, toFunc: Option[Function]): Unit = {
toFunc.foreach(tls+=)
toFunc.foreach(f => tls += f)
}
override def visitUPtrField(objRef: Word, iRef: Word, toAddr: Word): Unit = {
......
......@@ -11,7 +11,7 @@ class NativeArgv(args: Seq[String]) extends AutoCloseable {
for ((arg, i) <- (args).zipWithIndex) {
argvOffs(i) = argvSB.length
argvSB ++= arg += '\0'
argvSB ++= arg += '\u0000'
}
val cArgvMem = NativeSupport.allocateManual(argvOffs.length * WORD_SIZE_BYTES.toInt)
......
......@@ -2,12 +2,10 @@ package uvm.refimpl.hail
import java.io.Reader
import scala.collection.JavaConversions._
import scala.collection.JavaConverters._
import scala.collection.mutable.HashMap
import org.antlr.v4.runtime.ANTLRInputStream
import org.antlr.v4.runtime.CommonTokenStream
import org.antlr.v4.runtime.ParserRuleContext
import org.antlr.v4.runtime._
import org.slf4j.LoggerFactory
import com.typesafe.scalalogging.Logger
......@@ -40,7 +38,7 @@ class HailScriptLoader(recordSourceInfo: Boolean = true)(implicit microVM: Micro
}
def loadHail(hailScript: String): Unit = {
val ais = new ANTLRInputStream(hailScript)
val ais = CharStreams.fromString(hailScript)
val ea = new AccumulativeAntlrErrorListener(hailScript)
val lexer = new HAILLexer(ais)
......@@ -78,7 +76,7 @@ class InstanceHailScriptLoader(microVM: MicroVM, memorySupport: MemorySupport, m
val hailObjMap = new HailObjMap
def loadTopLevel(ast: HailContext): Unit = {
ast.topLevelDef.map(_.getChild(0)) foreach {
ast.topLevelDef.asScala.map(_.getChild(0)) foreach {
case tl: FixedAllocContext => {
val hailName = tl.nam.getText
......@@ -208,7 +206,7 @@ class InstanceHailScriptLoader(microVM: MicroVM, memorySupport: MemorySupport, m
var cur: LValue = base
for (ic <- lv.indices) {
for (ic <- lv.indices.iterator.asScala) {
val index = evalIntExpr(ic.intExpr()).toLong
val newCur = cur.indexInto(index, ic)
val oldCur = cur
......@@ -269,7 +267,7 @@ class InstanceHailScriptLoader(microVM: MicroVM, memorySupport: MemorySupport, m
case il: RVIntContext => (2, mc.handleFromInt(il.intLiteral, 52))
case RVGlobalOf(gv: ConstInt) => (2, mc.handleFromConst(gv.id).asInstanceOf[MuIntValue])
case lst: RVListContext => {
val elems = lst.list.rv.toSeq
val elems = lst.list.rv.asScala.toSeq
elems match {
case Seq(rv1, rv2) => {
val (hr, del) = resForRefType(rv1)
......@@ -298,7 +296,7 @@ class InstanceHailScriptLoader(microVM: MicroVM, memorySupport: MemorySupport, m
if (lv.varLen.isDefined || lty.isInstanceOf[AbstractCompositeType]) {
rv match {
case lst: RVListContext => {
val elems = lst.list.rv.toSeq
val elems = lst.list.rv.asScala.toSeq
for ((innerRv, i) <- elems.zipWithIndex) {
val innerLv = lv.indexInto(i, innerRv)
assign(innerLv, innerRv)
......@@ -507,7 +505,7 @@ class InstanceHailScriptLoader(microVM: MicroVM, memorySupport: MemorySupport, m
}
def rvListCtxToSeq(rvc: RVListContext): Seq[RValueContext] = {
rvc.list.rv.toSeq
rvc.list.rv.asScala.toSeq
}
object RVGlobalOf {
......
......@@ -2,13 +2,11 @@ package uvm.refimpl.itpr
import uvm._
import uvm.comminsts._
import uvm.ir.irbuilder._
import uvm.refimpl._
import uvm.refimpl.mem._
import uvm.refimpl.nat.CDefs
import uvm.ssavariables._
import uvm.types._
import uvm.refimpl.nat.NativeMemoryAccessHelper
import uvm.ssavariables._
object IRBuilderCommInstExecutor {
implicit def toBinOptr(i: Int): BinOptr.Value = CDefs.toBinOptr(i)
......
package uvm.refimpl.nat
import java.nio.charset.StandardCharsets
import com.kenai.jffi.CallingConvention
import com.kenai.jffi.Closure
import com.kenai.jffi.Closure.Buffer
......@@ -14,9 +12,9 @@ import uvm.comminsts.CommInsts
import uvm.ir.irbuilder.IRBuilder
import uvm.refimpl._
import uvm.refimpl.MicroVM
import uvm.ssavariables.{ MemoryOrder, AtomicRMWOptr }
import uvm.ssavariables.Flag
import uvm.ssavariables.{ AtomicRMWOptr, MemoryOrder }
import uvm.ssavariables.BinOpStatus
import uvm.ssavariables.Flag
class ExposedMethod(name: String, jRetTy: JType, jParamTys: Array[JType], invokeFunc: Buffer => Unit) {
val closure = new SimpleClosure(name, invokeFunc)
......
......@@ -7,7 +7,6 @@ import com.typesafe.scalalogging.Logger
import uvm._
import uvm.ssavariables._
import uvm.types._
import uvm.clientsupport.text.Inst.GetIRef
object BundleChecker {
val logger: Logger = Logger(LoggerFactory.getLogger(getClass.getName))
......@@ -68,8 +67,6 @@ class BundleChecker {
val MutableMap = collection.mutable.HashMap
type MutableQueue[T] = collection.mutable.Queue[T]
val MutableQueue = collection.mutable.Queue
type MutableStack[T] = collection.mutable.Stack[T]
val MutableStack = collection.mutable.Stack
def checkBundle(bundle: Bundle, parentBundle: Option[GlobalBundle]): Unit = {
new BundleChecker(bundle, parentBundle).check()
......@@ -484,7 +481,7 @@ class BundleChecker {
}
}
case i: InstBinOp => {
import BinOptr._
import uvm.ssavariables.BinOptr._
i.op match {
case ADD | SUB | MUL | UDIV | SDIV | UREM | SREM | SHL | LSHR | ASHR | AND | OR | XOR => i.opndTy match {
case TypeInt(_) =>
......@@ -533,7 +530,7 @@ class BundleChecker {
}
}
case i: InstCmp => {
import CmpOptr._
import uvm.ssavariables.CmpOptr._
i.op match {
case EQ | NE => i.opndTy match {
case t: AbstractEQComparableType =>
......@@ -656,7 +653,7 @@ class BundleChecker {
}
}
case i: InstCmpXchg => {
import MemoryOrder._
import uvm.ssavariables.MemoryOrder._
checkPtrAndOpnd(i.ptr, i.loc.inferredType)
(i.ordSucc, i.ordFail) match {
case (NOT_ATOMIC, _) | (_, NOT_ATOMIC) => throw errorFBI(s"CMPXCHG cannot have NOT_ATOMIC order")
......
package uvm.clientsupport.text
import java.util.regex.Pattern
import org.scalatest.matchers.{MatchResult, Matcher}
trait TextOutputMatchers {
private val varPattern = Pattern compile "[@%]\\$(\\w+)"
private val specialPattern = Pattern compile "\\s+|[@%]\\$\\w+"
class IRTemplateMatcher(outputTemplate: String) extends Matcher[BundleBuilder] {
private val lines = outputTemplate split "\n" map (_.trim) filter (_.nonEmpty)
private lazy val varIndexes = lines map { line =>
val matcher = varPattern matcher line
var indexes = Seq.empty[String]
while (matcher.find) indexes :+= matcher group 1
indexes
}
private lazy val linePatterns = lines map (line => Pattern compile {
var pattern = "^"
var lastEnd = 0
val matcher = specialPattern matcher line
while (matcher.find) {
val slice = line.substring(lastEnd, matcher.start)
if (slice.nonEmpty) pattern += Pattern quote slice
if (matcher.group matches "\\s+") pattern += "\\s+"
else pattern += "([@%][\\w\\-.]+)"
lastEnd = matcher.end
}
if (lastEnd < line.length) pattern += (Pattern quote (line substring lastEnd))
pattern + "$"
})
override def apply(left: BundleBuilder): MatchResult = {
val ir = left.build().toString
val testLines = ir split "\n" map (_.trim) filter (_.nonEmpty)
var varMap = Map.empty[String, String]
for ((((line, n), pattern), vars) <- testLines.zipWithIndex zip linePatterns zip varIndexes) {
val matcher = pattern matcher line
if (matcher.matches) {
for ((varName, index) <- vars.zipWithIndex) {
varMap get varName match {
case Some(value) =>
val newValue = matcher group (index+1)
if (newValue != value) return MatchResult(matches = false,