Commit cd3dd7d8 authored by Kunshan Wang's avatar Kunshan Wang

BundleSerializer test

parent ade25b5d
......@@ -87,7 +87,18 @@ class GlobalBundle extends Bundle {
}
}
private def redefineFunctions(newNs: Namespace[FuncVer]) {
private def declareFunctions(newNs: Namespace[Function]) {
for (func <- newNs.all) {
funcToVers.get(func) match {
case None => funcToVers(func) = Nil
case Some(fvs) => throw new UvmException(
"Function %s already declared or defined. Existing versions: { %s }".format(
func.repr, fvs.map(_.repr).mkString(", ")))
}
}
}
private def defineFunctions(newNs: Namespace[FuncVer]) {
for (fv <- newNs.all) {
val func = fv.func
val oldVers = funcToVers.getOrElse(func, Nil)
......@@ -121,7 +132,8 @@ class GlobalBundle extends Bundle {
simpleMerge(expFuncNs, newBundle.expFuncNs, newBundle.sourceInfoRepo)
simpleMerge(instNs, newBundle.instNs, newBundle.sourceInfoRepo)
redefineFunctions(newBundle.funcVerNs)
declareFunctions(newBundle.funcNs)
defineFunctions(newBundle.funcVerNs)
mergeLocalNamespaces(newBundle)
......
......@@ -345,7 +345,7 @@ abstract class InterpreterFrame(val prev: Option[InterpreterFrame]) {
object InterpreterFrame {
def forMuFunc(savedStackPointer: Word, func: Function, cookie: Long, prev: Option[InterpreterFrame])(implicit microVM: MicroVM): MuFrame = {
val frm = microVM.globalBundle.funcToVers.getOrElse(func, Nil).headOption match {
val frm = microVM.globalBundle.funcToVers(func).headOption match {
case None => new UndefinedMuFrame(func, prev)
case Some(funcVer) => new DefinedMuFrame(savedStackPointer, funcVer, cookie, prev)
}
......
package uvm.ir.textoutput
import uvm.GlobalBundle
import uvm.UvmTestBase
import uvm.TrantientBundle
import uvm.utils.IDFactory
import uvm.ir.textinput.UIRTextReader
import uvm.ir.textinput.TestingBundlesValidators
import com.typesafe.scalalogging.Logger
import org.slf4j.LoggerFactory
import java.io.StringWriter
import java.io.StringReader
import java.io.Reader
object BundleSerializerSmokeTest {
val logger = Logger(LoggerFactory.getLogger(getClass.getName))
}
class BundleSerializerSmokeTest extends UvmTestBase with TestingBundlesValidators {
import BundleSerializerSmokeTest._
def parseReader(reader: Reader, globalBundle: GlobalBundle, fac: Option[IDFactory] = None): TrantientBundle = {
val idf = fac.getOrElse(new IDFactory(uvm.refimpl.MicroVM.FIRST_CLIENT_USABLE_ID))
val r = new UIRTextReader(idf)
val ir = r.read(reader, globalBundle)
ir
}
def parseFile(fileName: String, globalBundle: GlobalBundle, fac: Option[IDFactory] = None): TrantientBundle = {
parseReader(new java.io.FileReader(fileName), globalBundle, fac)
}
behavior of "BundleSerializer"
def parseFresh(fileName: String): GlobalBundle = {
val gb = new GlobalBundle()
logger.info("Parsing (fresh) %s ...".format(fileName))
val tb = parseFile(fileName, gb)
gb.merge(tb)
logger.info("Dumping loaded bundle...")
val sw = new StringWriter()
val bs = new BundleSerializer(gb, None)
bs.writeUIR(sw)
val bTxt = sw.toString()
logger.debug("Bundle:\n" + bTxt)
val gb2 = new GlobalBundle()
val sr = new StringReader(bTxt)
logger.info("Load bundle again ...".format(fileName))
val tb2 = parseReader(sr, gb2)
gb2.merge(tb2)
gb2
}
it should "reload simple type definitions" in {
val b = parseFresh("tests/uvm-parsing-test/types.uir")
validateTypes(b)
}
it should "reload simple constant definitions" in {
val b = parseFresh("tests/uvm-parsing-test/constants.uir")
validateConstants(b)
}
it should "reload simple function definitions" in {
val b = parseFresh("tests/uvm-parsing-test/functions.uir")
validateFunctions(b)
}
it should "reload simple instruction definitions" in {
val b = parseFresh("tests/uvm-parsing-test/instructions.uir")
validateInstructions(b)
}
/*
it should "handle loading of multiple bundles" in {
val idf = new IDFactory()
val gb = new GlobalBundle()
val b1 = parseFile("tests/uvm-parsing-test/redef-base.uir", gb, Some(idf))
gb.merge(b1)
val b2 = parseFile("tests/uvm-parsing-test/redef-overlay.uir", gb, Some(idf))
validateRedef(gb, b1, b2)
gb.merge(b2)
validateRedefAfterMerge(gb, b2)
}
*/
}
\ No newline at end of file
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