Commit 948473b4 authored by Kunshan Wang's avatar Kunshan Wang

Function merging

parent 9431b7ce
......@@ -4,37 +4,50 @@ import uvm.types._
import uvm.ssavariables._
class Bundle {
/**
* Namespace of all SSA variables, global or local.
/*
* 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)
*
* TODO: Should there be a global "basic block ns for all function versions"?
*/
val varNs = new SimpleNamespace[SSAVariable]()
/**
* All global SSA varaibles.
*/
val globalVarNs = new SimpleNamespace[GlobalVariable]()
val typeNs = new SimpleNamespace[Type]()
val funcSigNs = new SimpleNamespace[FuncSig]()
val funcVerNs = new SimpleNamespace[FuncVer]()
val varNs = new SimpleNamespace[SSAVariable]()
val globalVarNs = new SimpleNamespace[GlobalVariable]()
val constantNs = new SimpleNamespace[Constant]()
val globalCellNs = new SimpleNamespace[GlobalCell]()
val funcNs = new SimpleNamespace[Function]()
val funcVerNs = new SimpleNamespace[FuncVer]()
private def simpleMerge[T <: Identified](oldNs: Namespace[T], newNs: Namespace[T]) {
for (cand <- newNs.all) {
try {
oldNs.add(cand)
} catch {
case e: NameConflictException =>
throw new IllegalRedefinitionException(
"Redefinition of type, function signature, constant or" +
" global cell is not allowed", e);
if (!cand.isInstanceOf[Function] || oldNs.get(cand.id) == None) {
// Function merging happens separately. Only add a function if it does not redefine an old one.
try {
oldNs.add(cand)
} catch {
case e: NameConflictException =>
throw new IllegalRedefinitionException(
"Redefinition of type, function signature, constant or" +
" global cell is not allowed", e);
}
}
}
}
private def mergeFunc(oldNs: Namespace[Function], newNs: Namespace[Function]) {
for (cand <- newNs.all) {
val id = cand.id
......
......@@ -215,6 +215,15 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
its fields 0 shouldBe (our globalValue "@gi64")
its fields 1 shouldBe (our globalValue "@fdummy")
}
// Testing namespaces
var ci8 = our const "@ci8"
our globalValue "@ci8" shouldBe ci8
our value "@ci8" shouldBe ci8
var gi64 = our globalCell "@gi64"
our globalValue "@gi64" shouldBe gi64
our value "@gi64" shouldBe gi64
}
def validateFunctions(bundle: Bundle) {
......@@ -279,6 +288,21 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
whose.index shouldEqual 1
}
}
// Testing namespaces
val main = our func "@main"
our globalValue "@main" shouldBe main
our value "@main" shouldBe main
val mainV1 = our funcVer "@main_v1"
val argcGN = "@main_v1.argc"
val argc = mainV1.localVarNs(argcGN)
our value argcGN shouldBe argc
val addGN = "@main_v1.add"
val add = mainV1.localVarNs(addGN)
our value addGN shouldBe add
}
def in(func: Function)(f: (Function, FuncVer) => Unit) {
......@@ -1009,6 +1033,10 @@ trait TestingBundlesValidators extends Matchers with ExtraMatchers {
(ourGlobal func "@foxsay").versions.head shouldBe (ourNew funcVer "@foxsay_v1")
(ourGlobal func "@meaning_of_life").versions.head shouldBe (ourNew funcVer "@meaning_of_life_v2")
val foxSay = ourGlobal func "@foxsay"
ourGlobal value "@foxsay" shouldBe foxSay
ourGlobal globalValue "@foxsay" shouldBe foxSay
}
}
\ No newline at end of file
......@@ -41,8 +41,8 @@ class UIRTextReaderSpec extends FlatSpec with Matchers
val b = parseFile("tests/uvm-parsing-test/redef-overlay.uir", gb, Some(idf))
validateRedef(gb, b)
//gb.merge(b)
//validateRedefAfterMerge(gb, b)
gb.merge(b)
validateRedefAfterMerge(gb, b)
}
}
\ No newline at end of file
......@@ -24,6 +24,7 @@
.funcdef @main VERSION @main_v1 <@baz> (%argc %argv) {
%entry:
%add = ADD <@i32> %argc @zero
RET <@i32> @zero
}
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