WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 559c72dc authored by Kunshan Wang's avatar Kunshan Wang
Browse files

Tested parser.

parent 3323a4b7
...@@ -2,8 +2,9 @@ package uvm ...@@ -2,8 +2,9 @@ package uvm
import uvm.types._ import uvm.types._
import uvm.ssavariables._ import uvm.ssavariables._
import scala.collection.mutable.HashMap
class Bundle { abstract class Bundle {
/* /*
* There is a hierarchy of namespaces. A subnode is a subset of the parent. * There is a hierarchy of namespaces. A subnode is a subset of the parent.
* *
...@@ -35,7 +36,30 @@ class Bundle { ...@@ -35,7 +36,30 @@ class Bundle {
val globalCellNs = globalVarNs.makeSubSpace[GlobalCell]() val globalCellNs = globalVarNs.makeSubSpace[GlobalCell]()
val funcNs = globalVarNs.makeSubSpace[Function]() val funcNs = globalVarNs.makeSubSpace[Function]()
val expFuncNs = globalVarNs.makeSubSpace[ExposedFunc]() val expFuncNs = globalVarNs.makeSubSpace[ExposedFunc]()
}
/**
* This kind of bundle is generated when parsing a .UIR file.
* <p>
* In this kind of bundle, a Function does not have a FuncVer as its version.
* The funcNs only contains new functions declared in this bundle, not existing
* functions declared previously. When this bundle is merged with the global bundle,
* both funcNs and funcVerNs are simply merged, and new FuncVer objects become the
* newest version of the Function, whether the Function is newly declared or not.
*/
class TrantientBundle extends Bundle {
/**
* All functions (declared here or previously) that are defined in this bundle.
* <p>
* Mainly for debugging purpose.
*/
//val defFuncNs = new SimpleNamespace[Function]
}
/**
* This kind of bundle holds the global state. Functions and versions are fully merged.
*/
class GlobalBundle extends Bundle {
private def simpleMerge[T <: Identified](oldNs: Namespace[T], newNs: Namespace[T]) { private def simpleMerge[T <: Identified](oldNs: Namespace[T], newNs: Namespace[T]) {
for (cand <- newNs.all) { for (cand <- newNs.all) {
try { try {
...@@ -49,7 +73,13 @@ class Bundle { ...@@ -49,7 +73,13 @@ class Bundle {
} }
} }
def merge(newBundle: Bundle) { private def redefineFunctions(newNs: Namespace[FuncVer]) {
for (fv <- newNs.all) {
fv.func.versions = fv :: fv.func.versions
}
}
def merge(newBundle: TrantientBundle) {
// Only merge leaves // Only merge leaves
simpleMerge(typeNs, newBundle.typeNs) simpleMerge(typeNs, newBundle.typeNs)
simpleMerge(funcSigNs, newBundle.funcSigNs) simpleMerge(funcSigNs, newBundle.funcSigNs)
...@@ -58,5 +88,8 @@ class Bundle { ...@@ -58,5 +88,8 @@ class Bundle {
simpleMerge(globalCellNs, newBundle.globalCellNs) simpleMerge(globalCellNs, newBundle.globalCellNs)
simpleMerge(funcNs, newBundle.funcNs) simpleMerge(funcNs, newBundle.funcNs)
simpleMerge(expFuncNs, newBundle.expFuncNs) simpleMerge(expFuncNs, newBundle.expFuncNs)
redefineFunctions(newBundle.funcVerNs)
} }
}
}
\ No newline at end of file
...@@ -18,12 +18,12 @@ class UIRTextReader(val idFactory: IDFactory) { ...@@ -18,12 +18,12 @@ class UIRTextReader(val idFactory: IDFactory) {
import UIRTextReader._ import UIRTextReader._
import uvm.ir.textinput.Later.Laterable import uvm.ir.textinput.Later.Laterable
def read(ir: String, globalBundle: Bundle): Bundle = { def read(ir: String, globalBundle: GlobalBundle): TrantientBundle = {
val input = new ANTLRInputStream(ir) val input = new ANTLRInputStream(ir)
read(ir, input, globalBundle) read(ir, input, globalBundle)
} }
def read(ir: java.io.Reader, globalBundle: Bundle): Bundle = { def read(ir: java.io.Reader, globalBundle: GlobalBundle): TrantientBundle = {
val sb = new StringBuilder() val sb = new StringBuilder()
val cb = new Array[Char](4096) val cb = new Array[Char](4096)
...@@ -57,7 +57,7 @@ class UIRTextReader(val idFactory: IDFactory) { ...@@ -57,7 +57,7 @@ class UIRTextReader(val idFactory: IDFactory) {
def getMessages(): String = buf.mkString("\n") def getMessages(): String = buf.mkString("\n")
} }
def read(source: String, ais: ANTLRInputStream, globalBundle: Bundle): Bundle = { def read(source: String, ais: ANTLRInputStream, globalBundle: GlobalBundle): TrantientBundle = {
val ea = new AccumulativeAntlrErrorListener(source) val ea = new AccumulativeAntlrErrorListener(source)
val lexer = new UIRLexer(ais) val lexer = new UIRLexer(ais)
...@@ -144,8 +144,8 @@ class UIRTextReader(val idFactory: IDFactory) { ...@@ -144,8 +144,8 @@ class UIRTextReader(val idFactory: IDFactory) {
case e: Exception => throw new TextIRParsingException(inCtx(ctx, s), e) case e: Exception => throw new TextIRParsingException(inCtx(ctx, s), e)
} }
def read(ir: IrContext, globalBundle: Bundle): Bundle = { def read(ir: IrContext, globalBundle: GlobalBundle): TrantientBundle = {
val bundle = new Bundle() val bundle = new TrantientBundle()
// Resolve global entities. (If any resXxxx is not present, that's because it is simply not currently used) // Resolve global entities. (If any resXxxx is not present, that's because it is simply not currently used)
...@@ -364,6 +364,7 @@ class UIRTextReader(val idFactory: IDFactory) { ...@@ -364,6 +364,7 @@ class UIRTextReader(val idFactory: IDFactory) {
} }
case fdef: FuncDefContext => { case fdef: FuncDefContext => {
val func = findOldFunc(fdef.nam).getOrElse(declFunc(fdef.nam, fdef.funcSig)) val func = findOldFunc(fdef.nam).getOrElse(declFunc(fdef.nam, fdef.funcSig))
//bundle.defFuncNs.add(func)
funcDefs += ((func, fdef)) funcDefs += ((func, fdef))
} }
case edef: FuncExpDefContext => { case edef: FuncExpDefContext => {
...@@ -385,7 +386,7 @@ class UIRTextReader(val idFactory: IDFactory) { ...@@ -385,7 +386,7 @@ class UIRTextReader(val idFactory: IDFactory) {
addFuncVer(ver) addFuncVer(ver)
ver.func = func ver.func = func
func.versions = ver :: func.versions //func.versions = ver :: func.versions // Don't override here. Let the MicroVM redefine functions.
def globalizeBB(name: String): String = globalize(name, verName) def globalizeBB(name: String): String = globalize(name, verName)
......
...@@ -153,7 +153,6 @@ case class KillOld() extends CurStackAction ...@@ -153,7 +153,6 @@ case class KillOld() extends CurStackAction
abstract class NewStackAction abstract class NewStackAction
case class PassValue(var argTy: Type, var arg: SSAVariable) extends NewStackAction case class PassValue(var argTy: Type, var arg: SSAVariable) extends NewStackAction
case class PassVoid() extends NewStackAction
case class ThrowExc(var exc: SSAVariable) extends NewStackAction case class ThrowExc(var exc: SSAVariable) extends NewStackAction
/** /**
......
...@@ -717,6 +717,6 @@ class TextIRWriterTest extends FlatSpec with Matchers { ...@@ -717,6 +717,6 @@ class TextIRWriterTest extends FlatSpec with Matchers {
println(ir) println(ir)
val muBundle = new UIRTextReader(new IDFactory).read(ir, new uvm.Bundle()) val muBundle = new UIRTextReader(new IDFactory).read(ir, new uvm.GlobalBundle())
} }
} }
\ No newline at end of file
...@@ -3,25 +3,25 @@ package uvm.ir.textinput ...@@ -3,25 +3,25 @@ package uvm.ir.textinput
import org.scalatest.FlatSpec import org.scalatest.FlatSpec
import org.scalatest.Matchers import org.scalatest.Matchers
import uvm.Bundle import uvm.GlobalBundle
import uvm.TrantientBundle
class NicerErrorMessage extends FlatSpec with Matchers class NicerErrorMessage extends FlatSpec with Matchers
with TestingBundlesValidators { with TestingBundlesValidators {
def parseFile(fileName: String, globalBundle: Bundle, fac: Option[IDFactory] = None): Bundle = { def parseFile(fileName: String, globalBundle: GlobalBundle, fac: Option[IDFactory] = None): TrantientBundle = {
val idf = fac.getOrElse(new IDFactory()) val idf = fac.getOrElse(new IDFactory())
val r = new UIRTextReader(idf) val r = new UIRTextReader(idf)
val ir = r.read(new java.io.FileReader(fileName), globalBundle) val ir = r.read(new java.io.FileReader(fileName), globalBundle)
ir ir
} }
val EMPTY_BUNDLE = new Bundle()
behavior of "UIRTextReader" behavior of "UIRTextReader"
it should "give nice error messages" in { it should "give nice error messages" in {
try { try {
val b = parseFile("tests/uvm-parsing-test/bundle-with-error.uir", EMPTY_BUNDLE) val gb = new GlobalBundle()
val b = parseFile("tests/uvm-parsing-test/bundle-with-error.uir", gb)
} catch { } catch {
case e: TextIRParsingException => // expected case e: TextIRParsingException => // expected
e.printStackTrace() e.printStackTrace()
......
...@@ -3,10 +3,9 @@ package uvm.ir.textinput ...@@ -3,10 +3,9 @@ package uvm.ir.textinput
import org.scalatest._ import org.scalatest._
import uvm._ import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.comminsts._ import uvm.comminsts._
import UIRTextReader.globalize import uvm.ssavariables._
import uvm.types._
trait TestingBundlesValidators extends Matchers with ExtraMatchers { trait TestingBundlesValidators extends Matchers with ExtraMatchers {
...@@ -22,7 +21,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers { ...@@ -22,7 +21,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
def funcVer(s: String) = b.funcVerNs(s) def funcVer(s: String) = b.funcVerNs(s)
def expFunc(s: String) = b.expFuncNs(s) def expFunc(s: String) = b.expFuncNs(s)
} }
implicit class MagicalThe(c: FuncVer) { implicit class MagicalThe(c: FuncVer) {
def globalName(s: String) = UIRTextReader.globalize(s, c.name.get) def globalName(s: String) = UIRTextReader.globalize(s, c.name.get)
def bb(s: String) = c.bbNs(UIRTextReader.globalize(s, c.name.get)) def bb(s: String) = c.bbNs(UIRTextReader.globalize(s, c.name.get))
...@@ -35,7 +34,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers { ...@@ -35,7 +34,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
def inst(s: String) = d.localVarNs(UIRTextReader.globalize(s, d.name.get)) def inst(s: String) = d.localVarNs(UIRTextReader.globalize(s, d.name.get))
} }
def validateTypes(bundle: Bundle) { def validateTypes(bundle: GlobalBundle) {
val our = bundle val our = bundle
our ty "@i1" shouldBeATypeIntOf(1) our ty "@i1" shouldBeATypeIntOf(1)
...@@ -149,7 +148,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers { ...@@ -149,7 +148,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our anything "@sig0" shouldBe sig0 our anything "@sig0" shouldBe sig0
} }
def validateConstants(bundle: Bundle) { def validateConstants(bundle: GlobalBundle) {
val our = bundle val our = bundle
our const "@ci8" shouldBeAConstIntOf (8, 127) our const "@ci8" shouldBeAConstIntOf (8, 127)
...@@ -268,7 +267,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers { ...@@ -268,7 +267,7 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
our anything "@gi64" shouldBe gi64 our anything "@gi64" shouldBe gi64
} }
def validateFunctions(bundle: Bundle) { def validateFunctions(bundle: GlobalBundle) {
val our = bundle val our = bundle
our sig "@foo" shouldBeA[FuncSig] { its => our sig "@foo" shouldBeA[FuncSig] { its =>
...@@ -359,12 +358,16 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers { ...@@ -359,12 +358,16 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
val ver = func.versions.head val ver = func.versions.head
f(func, ver) f(func, ver)
} }
def in(funcVer: FuncVer)(f: FuncVer => Unit) {
f(funcVer)
}
def in(b: BasicBlock)(f: BasicBlock => Unit) { def in(b: BasicBlock)(f: BasicBlock => Unit) {
f(b) f(b)
} }
def validateInstructions(bundle: Bundle) { def validateInstructions(bundle: GlobalBundle) {
val our = bundle val our = bundle
in (our func "@intBinOpTest") { (func, the) => in (our func "@intBinOpTest") { (func, the) =>
...@@ -725,539 +728,590 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers { ...@@ -725,539 +728,590 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
} }
} }
/*
in (our func "@aggregate") { (func, the) => in (our func "@aggregate") { (func, the) =>
val my = ver in(the bb "%entry") { my =>
my inst "%e0" shouldBeA[InstExtractValue] { its =>
its.strTy shouldBe (our ty "@sid")
its.index shouldBe 0
its.opnd shouldBe (our value "@sid1")
}
my inst "%e1" shouldBeA[InstExtractValue] { its =>
its.strTy shouldBe (our ty "@sid")
its.index shouldBe 1
its.opnd shouldBe (our value "@sid1")
}
my inst "%i0" shouldBeA[InstInsertValue] { its =>
its.strTy shouldBe (our ty "@sid")
its.index shouldBe 0
its.opnd shouldBe (our value "@sid1")
its.newVal shouldBe (our value "@I64_0")
}
my inst "%i1" shouldBeA[InstInsertValue] { its =>
its.strTy shouldBe (our ty "@sid")
its.index shouldBe 1
its.opnd shouldBe (our value "@sid1")
its.newVal shouldBe (our value "@D_0")
}
my inst "%ee0" shouldBeA[InstExtractElement] { its =>
its.vecTy shouldBe (our ty "@4xfloat")
its.indTy shouldBe (our ty "@i32")
its.opnd shouldBe (our value "@v1")
its.index shouldBe (our value "@I32_0")
}
my inst "%ie0" shouldBeA[InstInsertElement] { its =>
its.vecTy shouldBe (our ty "@4xfloat")
its.indTy shouldBe (our ty "@i32")
its.opnd shouldBe (our value "@v1")
its.index shouldBe (our value "@I32_1")
its.newVal shouldBe (our value "@F_1")
}
my inst "%sv0" shouldBeA[InstShuffleVector] { its => my inst "%e0" shouldBeA[InstExtractValue] { its =>
its.vecTy shouldBe (our ty "@4xfloat") its.strTy shouldBe (our ty "@sid")
its.maskTy shouldBe (our ty "@4xi32") its.index shouldBe 0
its.vec1 shouldBe (our value "@v1") its.opnd shouldBe (our value "@sid1")
its.vec2 shouldBe (our value "@v2") }
its.mask shouldBe (our value "@vshf")
my inst "%e1" shouldBeA[InstExtractValue] { its =>
its.strTy shouldBe (our ty "@sid")
its.index shouldBe 1
its.opnd shouldBe (our value "@sid1")
}
my inst "%i0" shouldBeA[InstInsertValue] { its =>
its.strTy shouldBe (our ty "@sid")
its.index shouldBe 0
its.opnd shouldBe (our value "@sid1")
its.newVal shouldBe (our value "@I64_0")
}
my inst "%i1" shouldBeA[InstInsertValue] { its =>
its.strTy shouldBe (our ty "@sid")
its.index shouldBe 1
its.opnd shouldBe (our value "@sid1")
its.newVal shouldBe (our value "@D_0")
}
my inst "%ee0" shouldBeA[InstExtractElement] { its =>
its.seqTy shouldBe (our ty "@4xfloat")
its.indTy shouldBe (our ty "@i32")
its.opnd shouldBe (our value "@v1")
its.index shouldBe (our value "@I32_0")
}
my inst "%ie0" shouldBeA[InstInsertElement] { its =>
its.seqTy shouldBe (our ty "@4xfloat")
its.indTy shouldBe (our ty "@i32")
its.opnd shouldBe (our value "@v1")
its.index shouldBe (our value "@I32_1")
its.newVal shouldBe (our value "@F_1")
}
my inst "%sv0" shouldBeA[InstShuffleVector] { its =>
its.vecTy shouldBe (our ty "@4xfloat")
its.maskTy shouldBe (our ty "@4xi32")
its.vec1 shouldBe (our value "@v1")
its.vec2 shouldBe (our value "@v2")
its.mask shouldBe (our value "@vshf")
}
} }
} }
in (our func "@memops") { (func, the) => in (our func "@memops") { (func, the) =>
val my = ver in(the bb "%entry") { my =>
my inst "%new" shouldBeA[InstNew] { its => my inst "%new" shouldBeA[InstNew] { its =>
its.allocTy shouldBe (our ty "@i64") its.allocTy shouldBe (our ty "@i64")
its.excClause shouldBe None its.excClause shouldBe None
} }
my inst "%newhybrid" shouldBeA[InstNewHybrid] { its => my inst "%newhybrid" shouldBeA[InstNewHybrid] { its =>
its.allocTy shouldBe (our ty "@hic") its.allocTy shouldBe (our ty "@hic")
its.lenTy shouldBe (our ty "@i64") its.lenTy shouldBe (our ty "@i64")
its.length shouldBe (my param "%p0") its.length shouldBe (my param "%p0")
its.excClause shouldBe None its.excClause shouldBe None
} }
my inst "%alloca" shouldBeA[InstAlloca] { its => my inst "%alloca" shouldBeA[InstAlloca] { its =>
its.allocTy shouldBe (our ty "@i64") its.allocTy shouldBe (our ty "@i64")
its.excClause shouldBe None its.excClause shouldBe None
} }
my inst "%allocahybrid" shouldBeA[InstAllocaHybrid] { its => my inst "%allocahybrid" shouldBeA[InstAllocaHybrid] { its =>
its.allocTy shouldBe (our ty "@hic") its.allocTy shouldBe (our ty "@hic")
its.lenTy shouldBe (our ty "@i64") its.lenTy shouldBe (our ty "@i64")
its.length shouldBe (my param "%p0") its.length shouldBe (my param "%p0")
its.excClause shouldBe None its.excClause shouldBe None
} }
my inst "%new_s" shouldBeA[InstNew] { its =>
its.allocTy shouldBe (our ty "@i64")
its.excClause shouldBe Some(ExcClause((my bb "%bb2"), (my bb "%handler")))
}
my inst "%newhybrid_s" shouldBeA[InstNewHybrid] { its =>
its.allocTy shouldBe (our ty "@hic")
its.lenTy shouldBe (our ty "@i64")
its.length shouldBe (my param "%p0")
its.excClause shouldBe Some(ExcClause((my bb "%bb3"), (my bb "%handler")))
}
my inst "%alloca_s" shouldBeA[InstAlloca] { its =>
its.allocTy shouldBe (our ty "@i64")
its.excClause shouldBe Some(ExcClause((my bb "%bb4"), (my bb "%handler")))
}
my inst "%allocahybrid_s" shouldBeA[InstAllocaHybrid] { its =>
its.allocTy shouldBe (our ty "@hic")
its.lenTy shouldBe (our ty "@i64")
its.length shouldBe (my param "%p0")
its.excClause shouldBe Some(ExcClause((my bb "%bb5"), (my bb "%handler")))
}
my inst "%new2" shouldBeA[InstNew] { its =>
its.allocTy shouldBe (our ty "@sid")
its.excClause shouldBe None
}
my inst "%alloca2" shouldBeA[InstAlloca] { its =>
its.allocTy shouldBe (our ty "@al")
its.excClause shouldBe None
}
my inst "%getiref" shouldBeA[InstGetIRef] { its =>
its.referentTy shouldBe (our ty "@sid")
its.opnd shouldBe (my inst "%new2")
}
my inst "%getfieldiref" shouldBeA[InstGetFieldIRef] { its =>
its.ptr shouldBe false
its.referentTy shouldBe (our ty "@sid")
its.index shouldBe 0
its.opnd shouldBe (my inst "%getiref")
}
my inst "%getelemiref" shouldBeA[InstGetElemIRef] { its =>
its.ptr shouldBe false
its.referentTy shouldBe (our ty "@al")
its.indTy shouldBe (our ty "@i64")
its.opnd shouldBe (my inst "%alloca2")
its.index shouldBe (my param "%p1")
}
my inst "%shiftiref" shouldBeA[InstShiftIRef] { its =>
its.ptr shouldBe false
its.referentTy shouldBe (our ty "@i8")
its.offTy shouldBe (our ty "@i64")
its.opnd shouldBe (my inst "%getvarpartiref")
its.offset shouldBe (my param "%p1")
}
my inst "%getfixedpartiref" shouldBeA[InstGetFixedPartIRef] { its => my inst "%new_s" shouldBeA[InstNew] { its =>
its.ptr shouldBe false its.allocTy shouldBe (our ty "@i64")
its.referentTy shouldBe (our ty "@hic") its.excClause shouldBe Some(ExcClause(
its.opnd shouldBe (my inst "%allocahybrid") DestClause(the bb "%bb2", Seq("%alloca", "%allocahybrid", "%p0", "%p1").map(my.value)),
DestClause(the bb "%handler", Seq())))
}
} }
in(the bb "%bb2") { my =>
my inst "%getvarpartiref" shouldBeA[InstGetVarPartIRef] { its =>
its.ptr shouldBe false my inst "%newhybrid_s" shouldBeA[InstNewHybrid] { its =>
its.referentTy shouldBe (our ty "@hic") its.allocTy shouldBe (our ty "@hic")
its.opnd shouldBe (my inst "%allocahybrid") its.lenTy shouldBe (our ty "@i64")
its.length shouldBe (my param "%p0")
its.excClause shouldBe Some(ExcClause(
DestClause(the bb "%bb3", Seq("%alloca", "%allocahybrid", "%p0", "%p1").map(my.value)),
DestClause(the bb "%handler", Seq())))
}
} }
in(the bb "%bb3") { my =>
my inst "%load" shouldBeA[InstLoad] { its =>
its.ptr shouldBe false my inst "%alloca_s" shouldBeA[InstAlloca] { its =>
its.ord shouldBe MemoryOrder.NOT_ATOMIC its.allocTy shouldBe (our ty "@i64")
its.referentTy shouldBe (our ty "@i64") its.excClause shouldBe Some(ExcClause(
its.loc shouldBe (my inst "%alloca")