Commit 57d9be2c authored by Kunshan Wang's avatar Kunshan Wang

irbuilder functions

parent 8c5043b9
......@@ -23,8 +23,7 @@ class Function extends GlobalVariable {
/**
* A version of a function. Also known as a "control flow graph".
*/
class FuncVer extends IdentifiedSettable {
var func: Function = null
class FuncVer(val func: Function) extends IdentifiedSettable {
var bbs: ArrayBuffer[BasicBlock] = null
def entry: BasicBlock = bbs.head
......@@ -33,7 +32,7 @@ class FuncVer extends IdentifiedSettable {
var bbNs: NestedNamespace[BasicBlock] = null // sub-namespace of allNs
}
class BasicBlock extends IdentifiedSettable {
class BasicBlock(val funcVer: FuncVer) extends IdentifiedSettable {
var norParams: ArrayBuffer[NorParam] = null
var excParam: Option[ExcParam] = null
var insts: ArrayBuffer[Instruction] = null
......
......@@ -311,14 +311,12 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
logger.debug("Phase 3")
def defFunc(func: Function, fDefCtx: FuncDefContext) {
logger.trace("Visiting function %s".format(func.name))
val ver = new FuncVer()
val ver = new FuncVer(func)
val verName = globalize(fDefCtx.ver, func.name.get)
ver.id = idFactory.getID()
ver.name = Some(verName)
addFuncVer(ver, toSourceInfo(fDefCtx.ver))
ver.func = func
ver.bbNs = bundle.allNs.makeSubSpace[BasicBlock]("basic block")
def addBB(bb: BasicBlock, sourceInfo: SourceInfo): Unit = addWithSourceInfo(ver.bbNs, bb, sourceInfo)
......@@ -340,7 +338,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
def makeBB(bbCtx: BasicBlockContext): BasicBlock = {
val label = bbCtx.label()
val bbName = globalize(label.name(), verName)
val bb = new BasicBlock()
val bb = new BasicBlock(ver)
bb.id = idFactory.getID()
bb.name = Some(bbName)
addBB(bb, toSourceInfo(bbCtx))
......@@ -469,7 +467,7 @@ private[textinput] class InstanceUIRTextReader(idFactory: IDFactory, source: Str
case ii: InstSwitchContext =>
InstSwitch(ii.`type`, null, null, null).later(phase4) { i =>
i.opnd = ii.opnd; i.defDest = ii.defDest
i.cases = for ((v, d) <- ii.caseVal.zip(ii.caseDest)) yield (resVar(v), resDestClause(d))
i.cases = (for ((v, d) <- ii.caseVal.zip(ii.caseDest)) yield (resVar(v), resDestClause(d))).to[ArrayBuffer]
}
case ii: InstCallContext =>
InstCall(null, null, null, null, null).later(phase4) { i =>
......
This diff is collapsed.
......@@ -118,7 +118,7 @@ trait CallLike extends HasArgList {
case class DestClause(val bb: BasicBlock, val args: Seq[SSAVariable])
case class ExcClause(val nor: DestClause, val exc: DestClause)
case class ExcClause(var nor: DestClause, var exc: DestClause)
trait HasExcClause extends Instruction with MaybeTerminator {
var excClause: Option[ExcClause]
......@@ -185,7 +185,7 @@ case class InstBranch(var dest: DestClause) extends Instruction with Terminator
case class InstBranch2(var cond: SSAVariable, var ifTrue: DestClause, var ifFalse: DestClause) extends Instruction with Terminator
case class InstSwitch(var opndTy: Type, var opnd: SSAVariable, var defDest: DestClause,
var cases: Seq[(SSAVariable, DestClause)]) extends Instruction with Terminator
var cases: ArrayBuffer[(SSAVariable, DestClause)]) extends Instruction with Terminator
case class InstCall(var sig: FuncSig, var callee: SSAVariable, var argList: Seq[SSAVariable],
var excClause: Option[ExcClause], var keepAlives: Seq[LocalVariable])
......
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