GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

Commit 5a852f01 authored by Kunshan Wang's avatar Kunshan Wang

Added an "allNs" for all identified entities.

parent 948473b4
......@@ -7,20 +7,23 @@ class Bundle {
/*
* There is a hierarchy of namespaces. A subnode is a subset of the parent.
*
* + typeNs // All types
* + funcSigNs // All function signatures
* + funcVerNs // All function versions
* + varNs // All variables, global or local
* + globalVarNs // Global variables
* + constantNs // Constants
* + globalCellNs // Global cells
* + funcNs // Functions
* + localVarNs // Local variables (per function version)
* + bbNs // Basic blocks (per function version)
* + allNs // All Identified entities
* + typeNs // All types
* + funcSigNs // All function signatures
* + funcVerNs // All function versions
* + varNs // All variables, global or local
* + globalVarNs // Global variables
* + constantNs // Constants
* + globalCellNs // Global cells
* + funcNs // Functions
* + localVarNs // Local variables (per function version)
* + bbNs // Basic blocks (per function version)
*
* TODO: Should there be a global "basic block ns for all function versions"?
*/
val allNs = new SimpleNamespace[Identified]()
val typeNs = new SimpleNamespace[Type]()
val funcSigNs = new SimpleNamespace[FuncSig]()
val funcVerNs = new SimpleNamespace[FuncVer]()
......@@ -31,7 +34,6 @@ class Bundle {
val globalCellNs = new SimpleNamespace[GlobalCell]()
val funcNs = new SimpleNamespace[Function]()
private def simpleMerge[T <: Identified](oldNs: Namespace[T], newNs: Namespace[T]) {
for (cand <- newNs.all) {
if (!cand.isInstanceOf[Function] || oldNs.get(cand.id) == None) {
......@@ -57,14 +59,16 @@ class Bundle {
}
}
}
def merge(newBundle: Bundle) {
simpleMerge(varNs, newBundle.varNs)
simpleMerge(globalVarNs, newBundle.globalVarNs)
simpleMerge(allNs, newBundle.allNs)
simpleMerge(typeNs, newBundle.typeNs)
simpleMerge(funcSigNs, newBundle.funcSigNs)
simpleMerge(funcVerNs, newBundle.funcVerNs)
simpleMerge(varNs, newBundle.varNs)
simpleMerge(globalVarNs, newBundle.globalVarNs)
simpleMerge(constantNs, newBundle.constantNs)
simpleMerge(globalCellNs, newBundle.globalCellNs)
simpleMerge(funcVerNs, newBundle.funcVerNs)
mergeFunc(funcNs, newBundle.funcNs)
}
}
......@@ -138,19 +138,28 @@ class UIRTextReader(val idFactory: IDFactory) {
// Add entities to namespaces.
def addTy(obj: Type): Unit = bundle.typeNs.add(obj)
def addSig(obj: FuncSig): Unit = bundle.funcSigNs.add(obj)
def addTy(obj: Type): Unit = {
bundle.allNs.add(obj)
bundle.typeNs.add(obj)
}
def addSig(obj: FuncSig): Unit = {
bundle.allNs.add(obj)
bundle.funcSigNs.add(obj)
}
def addConst(obj: Constant): Unit = {
bundle.allNs.add(obj)
bundle.constantNs.add(obj)
bundle.globalVarNs.add(obj)
bundle.varNs.add(obj)
}
def addGlobalCell(obj: GlobalCell): Unit = {
bundle.allNs.add(obj)
bundle.globalCellNs.add(obj)
bundle.globalVarNs.add(obj)
bundle.varNs.add(obj)
}
def addFunc(obj: Function): Unit = {
bundle.allNs.add(obj)
bundle.funcNs.add(obj)
bundle.globalVarNs.add(obj)
bundle.varNs.add(obj)
......@@ -158,8 +167,12 @@ class UIRTextReader(val idFactory: IDFactory) {
def addLocalVar(obj: LocalVariable, localNs: Namespace[LocalVariable]) = {
localNs.add(obj)
bundle.varNs.add(obj)
bundle.allNs.add(obj)
}
def addFuncVer(obj: FuncVer): Unit = {
bundle.allNs.add(obj)
bundle.funcVerNs.add(obj)
}
def addFuncVer(obj: FuncVer): Unit = bundle.funcVerNs.add(obj)
// Resolve types, with parse-time checking.
......@@ -328,6 +341,7 @@ class UIRTextReader(val idFactory: IDFactory) {
bb.id = idFactory.getID()
bb.name = Some(globalize(bbCtx.label().name()))
ver.bbNs.add(bb)
bundle.allNs.add(bb)
bb.insts = bbCtx.inst.map(mkInst)
......
......@@ -11,6 +11,7 @@ import UIRTextReader.globalize
trait TestingBundlesValidators extends Matchers with ExtraMatchers {
implicit class MagicalOur(b: Bundle) {
def anything(s: String) = b.allNs(s)
def ty(s: String) = b.typeNs(s)
def const(s: String) = b.constantNs (s)
def value(s: String) = b.varNs(s)
......@@ -129,6 +130,13 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
its.elemTy shouldBe (our ty "@double")
its.len shouldEqual 2
}
// Testing namespaces
val i8 = our ty "@i8"
our anything "@i8" shouldBe i8
val sig0 = our sig "@sig0"
our anything "@sig0" shouldBe sig0
}
def validateConstants(bundle: Bundle) {
......@@ -217,13 +225,15 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
}
// Testing namespaces
var ci8 = our const "@ci8"
val ci8 = our const "@ci8"
our globalValue "@ci8" shouldBe ci8
our value "@ci8" shouldBe ci8
our anything "@ci8" shouldBe ci8
var gi64 = our globalCell "@gi64"
val gi64 = our globalCell "@gi64"
our globalValue "@gi64" shouldBe gi64
our value "@gi64" shouldBe gi64
our anything "@gi64" shouldBe gi64
}
def validateFunctions(bundle: Bundle) {
......@@ -293,16 +303,20 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
val main = our func "@main"
our globalValue "@main" shouldBe main
our value "@main" shouldBe main
our anything "@main" shouldBe main
val mainV1 = our funcVer "@main_v1"
our anything "@main_v1" shouldBe mainV1
val argcGN = "@main_v1.argc"
val argc = mainV1.localVarNs(argcGN)
our value argcGN shouldBe argc
our anything argcGN shouldBe argc
val addGN = "@main_v1.add"
val add = mainV1.localVarNs(addGN)
our value addGN shouldBe add
our anything addGN shouldBe add
}
def in(func: Function)(f: (Function, FuncVer) => Unit) {
......
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