Commit d7a76d9e authored by Kunshan Wang's avatar Kunshan Wang

New bundle building API. (not tested yet)

parent f0f14163
......@@ -563,10 +563,10 @@ struct MuIRBuilder {
// Create basic block. Also create its parameters.
void (*new_bb)(MuIRBuilder *b, MuID id,
MuID *nor_param_ids, MuArraySize n_nor_param_ids,
MuID *nor_param_ids, MuTypeNode *nor_param_types, MuArraySize n_nor_params,
MuID exc_param_id,
MuInstNode *insts, MuArraySize ninsts);
/// MUAPIPARSER nor_param_ids:array:n_nor_param_ids;exc_param_id:optional;insts:array:ninsts
/// MUAPIPARSER nor_param_ids:array:n_nor_params;nor_param_types:array:n_nor_params;exc_param_id:optional;insts:array:ninsts
// Create a destination clause.
void (*new_dest_clause)(MuIRBuilder *b, MuID id,
......@@ -694,9 +694,11 @@ struct MuIRBuilder {
/// MUAPIPARSER result_ids:array:nretvals;rettys:array:nretvals;exc_clause:optional;keepalive_clause:optional
void (*new_watchpoint)(MuIRBuilder *b, MuID id, MuWPID wpid,
MuID *result_ids, MuTypeNode *rettys, MuArraySize nretvals,
MuExcClause exc_clause, MuKeepaliveClause keepalive_clause);
/// MUAPIPARSER result_ids:array:nretvals;rettys:array:nretvals;exc_clause:optional;keepalive_clause:optional
void (*new_wpbranch )(MuIRBuilder *b, MuID id, MuWPID wpid);
MuDestClause dis, MuDestClause ena, MuDestClause exc,
MuKeepaliveClause keepalive_clause);
/// MUAPIPARSER result_ids:array:nretvals;rettys:array:nretvals;exc:optional;keepalive_clause:optional
void (*new_wpbranch )(MuIRBuilder *b, MuID id, MuWPID wpid,
MuDestClause dis, MuDestClause ena);
void (*new_ccall)(MuIRBuilder *b, MuID id, MuID *result_ids, MuArraySize n_result_ids,
MuCallConv callconv,
......
......@@ -155,7 +155,7 @@ instBody
| 'BRANCH' dest=destClause # InstBranch
| 'BRANCH2' cond=value ifTrue=destClause ifFalse=destClause # InstBranch2
| 'SWITCH' '<' ty=type '>' opnd=value defDest=destClause '{'
(caseVal+=value caseDest+=destClause )* '}' # InstSwitch
(caseVal+=constant caseDest+=destClause )* '}' # InstSwitch
// Inter-function Control Flow
| 'CALL' funcCallBody excClause keepaliveClause # InstCall
......
......@@ -29,7 +29,7 @@ object IRBuilder {
table
}
def validateName(name: String): String = {
def validateName(name: String): MuName = {
if (name.startsWith("%")) {
throw new IllegalNameException("Name must be global (starting with '@') when using the IR building API. Found: %s".format(name))
} else if (!name.startsWith("@")) {
......@@ -62,6 +62,7 @@ trait IRBuilderListener {
class IRBuilder(val id: MuInternalID,
globalBundle: GlobalBundle, idFactory: IDFactory, irBuilderListener: Option[IRBuilderListener])
extends HasID {
import IRBuilder._
import IRBuilderNode._
private def nextID(): Int = idFactory.getID()
......@@ -90,7 +91,7 @@ class IRBuilder(val id: MuInternalID,
def genSym(name: Option[String]): MuID = {
val id = nextID()
name foreach { n =>
idNameMap(id) = n
idNameMap(id) = validateName(n)
}
id
}
......@@ -218,8 +219,8 @@ class IRBuilder(val id: MuInternalID,
val _node = new NodeFuncVer(id, func, bbs)
onNewNodeCreated(_node)
}
def newBB(id: MuID, norParamIDs: Seq[MuID], excParamID: Option[MuID], insts: Seq[MuInstNode]): Unit = {
val _node = new NodeBB(id, norParamIDs, excParamID, insts)
def newBB(id: MuID, norParamIDs: Seq[MuID], norParamTys: Seq[MuTypeNode], excParamID: Option[MuID], insts: Seq[MuInstNode]): Unit = {
val _node = new NodeBB(id, norParamIDs, norParamTys, excParamID, insts)
onNewNodeCreated(_node)
}
def newDestClause(id: MuID, dest: MuBBNode, vars: Seq[MuVarNode]): Unit = {
......@@ -250,8 +251,8 @@ class IRBuilder(val id: MuInternalID,
val _node = new NodeNscThrowExc(id, exc)
onNewNodeCreated(_node)
}
def newBinOp(id: MuID, resultID: MuID, optr: BinOptr.Value, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode, excClaues: Option[MuExcClause]): Unit = {
val _node = new NodeBinOp(id, resultID, optr, ty, opnd1, opnd2, excClaues)
def newBinOp(id: MuID, resultID: MuID, optr: BinOptr.Value, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode, excClause: Option[MuExcClause]): Unit = {
val _node = new NodeBinOp(id, resultID, optr, ty, opnd1, opnd2, excClause)
onNewNodeCreated(_node)
}
def newCmp(id: MuID, resultID: MuID, optr: CmpOptr.Value, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode): Unit = {
......@@ -278,8 +279,8 @@ class IRBuilder(val id: MuInternalID,
val _node = new NodeSwitch(id, opndTy, opnd, defaultDest, cases, dests)
onNewNodeCreated(_node)
}
def newCall(id: MuID, resultIds: Seq[MuID], sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeCall(id, resultIds, sig, callee, args, excClause, keepaliveClause)
def newCall(id: MuID, resultIDs: Seq[MuID], sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeCall(id, resultIDs, sig, callee, args, excClause, keepaliveClause)
onNewNodeCreated(_node)
}
def newTailCall(id: MuID, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode]): Unit = {
......@@ -370,32 +371,32 @@ class IRBuilder(val id: MuInternalID,
val _node = new NodeFence(id, ord)
onNewNodeCreated(_node)
}
def newTrap(id: MuID, resultIds: Seq[MuID], rettys: Seq[MuTypeNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeTrap(id, resultIds, rettys, excClause, keepaliveClause)
def newTrap(id: MuID, resultIDs: Seq[MuID], rettys: Seq[MuTypeNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeTrap(id, resultIDs, rettys, excClause, keepaliveClause)
onNewNodeCreated(_node)
}
def newWatchPoint(id: MuID, wpid: MuWPID, resultIds: Seq[MuID], rettys: Seq[MuTypeNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeWatchPoint(id, wpid, resultIds, rettys, excClause, keepaliveClause)
def newWatchPoint(id: MuID, wpid: MuWPID, resultIDs: Seq[MuID], rettys: Seq[MuTypeNode], dis: MuDestClause, ena: MuDestClause, exc: Option[MuDestClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeWatchPoint(id, wpid, resultIDs, rettys, dis, ena, exc, keepaliveClause)
onNewNodeCreated(_node)
}
def newWPBranch(id: MuID, wpid: MuWPID): Unit = {
val _node = new NodeWPBranch(id, wpid)
def newWPBranch(id: MuID, wpid: MuWPID, dis: MuDestClause, ena: MuDestClause): Unit = {
val _node = new NodeWPBranch(id, wpid, dis, ena)
onNewNodeCreated(_node)
}
def newCCall(id: MuID, resultIds: Seq[MuID], callconv: Flag, calleeTy: MuTypeNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeCCall(id, resultIds, callconv, calleeTy, sig, callee, args, excClause, keepaliveClause)
def newCCall(id: MuID, resultIDs: Seq[MuID], callconv: Flag, calleeTy: MuTypeNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeCCall(id, resultIDs, callconv, calleeTy, sig, callee, args, excClause, keepaliveClause)
onNewNodeCreated(_node)
}
def newNewThread(id: MuID, resultID: MuID, stack: MuVarNode, threadlocal: Option[MuVarNode], newStackClause: MuNewStackClause, excClause: Option[MuExcClause]): Unit = {
val _node = new NodeNewThread(id, resultID, stack, threadlocal, newStackClause, excClause)
onNewNodeCreated(_node)
}
def newSwapStack(id: MuID, resultIds: Seq[MuID], swappee: MuVarNode, curStackClause: MuCurStackClause, newStackClause: MuNewStackClause, excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeSwapStack(id, resultIds, swappee, curStackClause, newStackClause, excClause, keepaliveClause)
def newSwapStack(id: MuID, resultIDs: Seq[MuID], swappee: MuVarNode, curStackClause: MuCurStackClause, newStackClause: MuNewStackClause, excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeSwapStack(id, resultIDs, swappee, curStackClause, newStackClause, excClause, keepaliveClause)
onNewNodeCreated(_node)
}
def newCommInst(id: MuID, resultIds: Seq[MuID], opcode: CommInst, flags: Seq[Flag], tys: Seq[MuTypeNode], sigs: Seq[MuFuncSigNode], args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeCommInst(id, resultIds, opcode, flags, tys, sigs, args, excClause, keepaliveClause)
def newCommInst(id: MuID, resultIDs: Seq[MuID], opcode: CommInst, flags: Seq[Flag], tys: Seq[MuTypeNode], sigs: Seq[MuFuncSigNode], args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
val _node = new NodeCommInst(id, resultIDs, opcode, flags, tys, sigs, args, excClause, keepaliveClause)
onNewNodeCreated(_node)
}
// GEN:END:IRBUILDERNODE_CONSTRUCTORS
......
......@@ -490,7 +490,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))).to[ArrayBuffer]
i.cases = (for ((v, d) <- ii.caseVal.zip(ii.caseDest)) yield (resConst(v), resDestClause(d))).to[ArrayBuffer]
}
case ii: InstCallContext =>
InstCall(null, null, null, null, null).later(phase4) { i =>
......
......@@ -1303,20 +1303,22 @@ val func = _raw_func
val bbs = readMuIDArray(_raw_bbs, _raw_nbbs)
val _RV = b.newFuncVer(id, func, bbs)
}
val MUIRBUILDER__NEW_BB = exposedMethod("MuIRBuilder.new_bb", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.POINTER, JType.POINTER, JType.UINT32, JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val MUIRBUILDER__NEW_BB = exposedMethod("MuIRBuilder.new_bb", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.POINTER, JType.POINTER, JType.POINTER, JType.UINT32, JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_b = _jffiBuffer.getAddress(0)
val _raw_id = _jffiBuffer.getInt(1)
val _raw_nor_param_ids = _jffiBuffer.getAddress(2)
val _raw_n_nor_param_ids = _jffiBuffer.getAddress(3)
val _raw_exc_param_id = _jffiBuffer.getInt(4)
val _raw_insts = _jffiBuffer.getAddress(5)
val _raw_ninsts = _jffiBuffer.getAddress(6)
val _raw_nor_param_types = _jffiBuffer.getAddress(3)
val _raw_n_nor_params = _jffiBuffer.getAddress(4)
val _raw_exc_param_id = _jffiBuffer.getInt(5)
val _raw_insts = _jffiBuffer.getAddress(6)
val _raw_ninsts = _jffiBuffer.getAddress(7)
val b = getMuIRBuilder(_raw_b)
val id = _raw_id
val nor_param_ids = readIntArray(_raw_nor_param_ids, _raw_n_nor_param_ids)
val nor_param_ids = readIntArray(_raw_nor_param_ids, _raw_n_nor_params)
val nor_param_types = readMuIDArray(_raw_nor_param_types, _raw_n_nor_params)
val exc_param_id = readMuIDOptional(_raw_exc_param_id)
val insts = readMuIDArray(_raw_insts, _raw_ninsts)
val _RV = b.newBB(id, nor_param_ids, exc_param_id, insts)
val _RV = b.newBB(id, nor_param_ids, nor_param_types, exc_param_id, insts)
}
val MUIRBUILDER__NEW_DEST_CLAUSE = exposedMethod("MuIRBuilder.new_dest_clause", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.UINT32, JType.POINTER, JType.POINTER)) { _jffiBuffer =>
val _raw_b = _jffiBuffer.getAddress(0)
......@@ -1900,32 +1902,40 @@ val exc_clause = readMuIDOptional(_raw_exc_clause)
val keepalive_clause = readMuIDOptional(_raw_keepalive_clause)
val _RV = b.newTrap(id, result_ids, rettys, exc_clause, keepalive_clause)
}
val MUIRBUILDER__NEW_WATCHPOINT = exposedMethod("MuIRBuilder.new_watchpoint", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.UINT32, JType.POINTER, JType.POINTER, JType.POINTER, JType.UINT32, JType.UINT32)) { _jffiBuffer =>
val MUIRBUILDER__NEW_WATCHPOINT = exposedMethod("MuIRBuilder.new_watchpoint", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.UINT32, JType.POINTER, JType.POINTER, JType.POINTER, JType.UINT32, JType.UINT32, JType.UINT32, JType.UINT32)) { _jffiBuffer =>
val _raw_b = _jffiBuffer.getAddress(0)
val _raw_id = _jffiBuffer.getInt(1)
val _raw_wpid = _jffiBuffer.getInt(2)
val _raw_result_ids = _jffiBuffer.getAddress(3)
val _raw_rettys = _jffiBuffer.getAddress(4)
val _raw_nretvals = _jffiBuffer.getAddress(5)
val _raw_exc_clause = _jffiBuffer.getInt(6)
val _raw_keepalive_clause = _jffiBuffer.getInt(7)
val _raw_dis = _jffiBuffer.getInt(6)
val _raw_ena = _jffiBuffer.getInt(7)
val _raw_exc = _jffiBuffer.getInt(8)
val _raw_keepalive_clause = _jffiBuffer.getInt(9)
val b = getMuIRBuilder(_raw_b)
val id = _raw_id
val wpid = _raw_wpid
val result_ids = readIntArray(_raw_result_ids, _raw_nretvals)
val rettys = readMuIDArray(_raw_rettys, _raw_nretvals)
val exc_clause = readMuIDOptional(_raw_exc_clause)
val dis = _raw_dis
val ena = _raw_ena
val exc = readMuIDOptional(_raw_exc)
val keepalive_clause = readMuIDOptional(_raw_keepalive_clause)
val _RV = b.newWatchPoint(id, wpid, result_ids, rettys, exc_clause, keepalive_clause)
val _RV = b.newWatchPoint(id, wpid, result_ids, rettys, dis, ena, exc, keepalive_clause)
}
val MUIRBUILDER__NEW_WPBRANCH = exposedMethod("MuIRBuilder.new_wpbranch", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.UINT32)) { _jffiBuffer =>
val MUIRBUILDER__NEW_WPBRANCH = exposedMethod("MuIRBuilder.new_wpbranch", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.UINT32, JType.UINT32, JType.UINT32)) { _jffiBuffer =>
val _raw_b = _jffiBuffer.getAddress(0)
val _raw_id = _jffiBuffer.getInt(1)
val _raw_wpid = _jffiBuffer.getInt(2)
val _raw_dis = _jffiBuffer.getInt(3)
val _raw_ena = _jffiBuffer.getInt(4)
val b = getMuIRBuilder(_raw_b)
val id = _raw_id
val wpid = _raw_wpid
val _RV = b.newWPBranch(id, wpid)
val dis = _raw_dis
val ena = _raw_ena
val _RV = b.newWPBranch(id, wpid, dis, ena)
}
val MUIRBUILDER__NEW_CCALL = exposedMethod("MuIRBuilder.new_ccall", JType.VOID, Array(JType.POINTER, JType.UINT32, JType.POINTER, JType.POINTER, JType.UINT32, JType.UINT32, JType.UINT32, JType.UINT32, JType.POINTER, JType.POINTER, JType.UINT32, JType.UINT32)) { _jffiBuffer =>
val _raw_b = _jffiBuffer.getAddress(0)
......
......@@ -193,7 +193,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: ArrayBuffer[(SSAVariable, DestClause)]) extends Instruction with Terminator
var cases: ArrayBuffer[(Constant, 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