Commit 6024297e authored by Kunshan Wang's avatar Kunshan Wang

WIP: Fixed UIR Parser.

parent 60d6faa0
......@@ -177,6 +177,7 @@ instBody
| 'TRAP' typeList excClause keepAliveClause # InstTrap
| 'WATCHPOINT' wpid=intLiteral typeList
dis=destClause ena=destClause ('WPEXC' '(' wpExc=destClause ')')? keepAliveClause # InstWatchPoint
| 'WPBRANCH' wpid=intLiteral dis=destClause ena=destClause # InstWPBranch
// Foreign Function Interface
| 'CCALL' callConv=flag '<' funcTy=type funcSig '>' callee=value argList excClause keepAliveClause # InstCCall
......
......@@ -20,6 +20,8 @@ abstract class Bundle {
* + expFuncNs // Exposed functions
* + localVarNs // Local variables (per basic block)
* + bbNs // Basic blocks (per function version)
* + instNs // All instructions
* + localInstNs // Instructions in a basic block (per basic block)
*
* bbNs and localVarNs are part of particular FuncVers and BBs.
*/
......@@ -36,6 +38,8 @@ abstract class Bundle {
val globalCellNs = globalVarNs.makeSubSpace[GlobalCell]()
val funcNs = globalVarNs.makeSubSpace[Function]()
val expFuncNs = globalVarNs.makeSubSpace[ExposedFunc]()
val instNs = allNs.makeSubSpace[Instruction]()
}
/**
......@@ -96,6 +100,7 @@ class GlobalBundle extends Bundle {
fv.bbNs.reparent(allNs)
for (bb <- fv.bbs) {
bb.localVarNs.reparent(allNs)
bb.localInstNs.reparent(allNs)
}
}
}
......@@ -109,6 +114,7 @@ class GlobalBundle extends Bundle {
simpleMerge(globalCellNs, newBundle.globalCellNs)
simpleMerge(funcNs, newBundle.funcNs)
simpleMerge(expFuncNs, newBundle.expFuncNs)
simpleMerge(instNs, newBundle.instNs)
redefineFunctions(newBundle.funcVerNs)
......
......@@ -11,7 +11,7 @@ object CommInsts extends SimpleNamespace[CommInst] {
add(ci)
}
commInst(0x201, "@uvm.new_thread")
commInst(0x201, "@uvm.new_stack")
commInst(0x202, "@uvm.kill_stack")
commInst(0x203, "@uvm.thread_exit")
commInst(0x204, "@uvm.current_stack")
......
......@@ -38,4 +38,5 @@ class BasicBlock extends IdentifiedSettable {
var insts: Seq[Instruction] = null
var localVarNs: NestedNamespace[LocalVariable] = null // sub-namespace of allNs
var localInstNs: NestedNamespace[Instruction] = null // sub-namespace of allNs
}
......@@ -402,6 +402,7 @@ class UIRTextReader(val idFactory: IDFactory) {
ver.bbNs.add(bb)
bb.localVarNs = bundle.allNs.makeSubSpace[LocalVariable]
bb.localInstNs = bundle.allNs.makeSubSpace[Instruction]
def mkNorParam(ty: Type, name: String): NorParam = {
val param = NorParam(ty)
......@@ -614,9 +615,13 @@ class UIRTextReader(val idFactory: IDFactory) {
i.excClause = ii.excClause; i.keepAlives = ii.keepAliveClause
}
case ii: InstWatchPointContext =>
InstWatchPoint(ii.intLiteral.intValue(), ii.typeList(), null, null, null, null).later(phase4) { i =>
InstWatchPoint(ii.wpid.intValue(), ii.typeList(), null, null, null, null).later(phase4) { i =>
i.dis = ii.dis; i.ena = ii.ena; i.exc = Option(ii.wpExc).map(resDestClause); i.keepAlives = ii.keepAliveClause
}
case ii: InstWPBranchContext =>
InstWPBranch(ii.wpid.intValue(), null, null).later(phase4) { i =>
i.dis = ii.dis; i.ena = ii.ena
}
case ii: InstCCallContext =>
InstCCall(ii.callConv, ii.funcTy, ii.funcSig, null, null, null, null).later(phase4) { i =>
i.callee = ii.callee; i.argList = ii.argList; i.excClause = ii.excClause; i.keepAlives = ii.keepAliveClause
......@@ -630,8 +635,8 @@ class UIRTextReader(val idFactory: IDFactory) {
case ii: InstSwapStackContext =>
InstSwapStack(null, null, null, null, null).later(phase4) { i =>
i.swappee = ii.swappee
i.curStackAction = ii.curStackClause
i.newStackAction = ii.newStackClause
i.curStackAction = ii.curStackClause
i.newStackAction = ii.newStackClause
i.excClause = ii.excClause; i.keepAlives = ii.keepAliveClause
}
case ii: InstCommInstContext =>
......@@ -645,16 +650,24 @@ class UIRTextReader(val idFactory: IDFactory) {
inst.id = idFactory.getID()
inst.name = Option(instDef.name).map(n => globalize(n.getText, bbName))
bb.localInstNs.add(inst)
val instRess: Seq[InstResult] = Option(instDef.instResults) match {
case None => Seq()
case Some(r) => for ((instResDef, index) <- r.results.zipWithIndex) yield {
val resName = globalize(instResDef.getText, bbName)
val instRes = InstResult(inst, index)
instRes.id = idFactory.getID()
instRes.name = Some(resName)
bb.localVarNs.add(instRes)
for ((instResDef, index) <- instDef.instResults().results.zipWithIndex) {
val resName = globalize(instResDef.getText, bbName)
val instRes = InstResult(inst, index)
instRes.id = idFactory.getID()
instRes.name = Some(resName)
bb.localVarNs.add(instRes)
instRes
}
}
inst.results = instRess
return inst
}
......
......@@ -41,6 +41,7 @@ class UIRTextReaderSpec extends FlatSpec with Matchers
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()
......@@ -52,5 +53,5 @@ class UIRTextReaderSpec extends FlatSpec with Matchers
gb.merge(b2)
validateRedefAfterMerge(gb, b2)
}
*/
}
\ No newline at end of file
......@@ -45,7 +45,7 @@
.typedef @rv = ref<@void>
.typedef @irv = iref<@void>
.typedef @wrv = weakref<@void>
.funcsig @sig0 = @void ()
.funcsig @sig0 = () -> ()
.typedef @func0 = funcref <@sig0>
.typedef @thread = threadref
.typedef @stack = stackref
......@@ -55,7 +55,6 @@
.const @cfu <@func0> = NULL
.const @cth <@thread> = NULL
.const @cst <@stack> = NULL
.const @VOID <@void> = NULL
.typedef @4xfloat = vector <@float 4>
.typedef @4xi32 = vector <@i32 4>
......
......@@ -7,25 +7,29 @@
.typedef @ii8 = iref<@i8>
.typedef @iii8 = iref<@ii8>
.funcsig @foo = @void ()
.funcsig @foo = () -> ()
.funcsig @bar = @i64 (@i32 @i16)
.funcsig @bar = (@i32 @i16) -> (@i64)
.funcsig @baz = @i32 (@i32 @iii8)
.funcsig @baz = (@i32 @iii8) -> (@i32)
.funcsig @sig_fs = @void (@i32)
.funcsig @sig_fs = (@i32) -> ()
.typedef @sig_t = funcref<@sig_fs>
.funcsig @signal_sig = @sig_t (@i32 @sig_t)
.funcsig @signal_sig = (@i32 @sig_t) -> (@sig_t)
.funcdecl @signal <@signal_sig>
.const @zero <@i32> = 0
.funcsig @multi.sig = () -> (@i8 @i16 @i32)
.funcdecl @multi <@multi.sig>
.funcdef @main VERSION %v1 <@baz> {
%entry(<@i32> %argc <@iii8> %argv):
%add = ADD <@i32> %argc @zero
RET @zero
%sum = [%add] ADD <@i32> %argc @zero
(%x %y %z) = [%call] CALL <@multi.sig> @multi ()
[%ret] RET %sum
}
.const @zero64 <@i64> = 0
......
This diff is collapsed.
.typedef @i64 = int<64>
.const @I64_42 <@i64> = 42
.funcsig @IntReturner = @i64 ()
.funcsig @IntReturner = () -> (@i64)
.funcdef @meaning_of_life VERSION %v1 <@IntReturner> {
%entry():
%ret = RET @I64_42
[%ret] RET @I64_42
}
.funcdecl @foxsay <@IntReturner>
......
......@@ -3,11 +3,11 @@
.funcdef @foxsay VERSION %v1 <@IntReturner> {
%entry():
%ret = RET @I64_99
[%ret] RET @I64_99
}
.funcdef @meaning_of_life VERSION %v2 <@IntReturner> {
%entry():
%ret = RET @I64_43
[%ret] RET @I64_43
}
.expose @meaning_external2 = @meaning_of_life #DEFAULT @I64_43
......@@ -24,16 +24,18 @@
.typedef @a1 = array<@foo 10>
.typedef @a2 = array<@a1 10>
.typedef @h0 = hybrid <@void @i8>
.typedef @h0 = hybrid <@i8>
.typedef @h1 = hybrid <@foo @i64>
.typedef @h2 = hybrid <@i8 @i16 @float @i64>
.typedef @void = void
.funcsig @sig0 = @void ()
.funcsig @sig0 = () -> ()
.typedef @ii8 = iref<@i8>
.typedef @iii8 = iref<@ii8>
.funcsig @sig1 = @i32 (@i32 @iii8)
.funcsig @sig1 = (@i32 @iii8) -> (@i32)
.funcsig @sig2 = (@i32 @iii8) -> (@i32 @i64)
.typedef @f0 = funcref <@sig0>
.typedef @f1 = funcref <@sig1>
......
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