GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 083afc1a authored by Kunshan Wang's avatar Kunshan Wang

WIP: cstubs generated

parent de2867ae
......@@ -155,6 +155,7 @@ _special_cases = {
"swapstack": "SwapStack",
"comminst": "CommInst",
"ir": "IR",
"irbuilderref": "IRBuilderRef",
}
def toCamelCase(name):
......@@ -174,12 +175,12 @@ def to_basic_type(typedefs, name):
return name
_no_conversion = {
"MuID", # It's just Int.
# "MuID", # It may be optional, in which case it needs conversion.
"MuTrapHandler", # It is a function pointer. Handle in Scala.
"MuCPtr", # Intended to be raw pointer. Passed directly.
"MuCFP", # ditto
"MuWPID", # Just Int
"MuCommInst", # Onlu used in new_comminst, and the builder uses opcode directly.
# "MuCommInst", # same as MuID
}
_array_converters = {
......@@ -198,7 +199,8 @@ _special_converters = {
"MuBinOptr" : "toBinOptr",
"MuCmpOptr" : "toCmpOptr",
"MuConvOptr" : "toConvOptr",
"MuCallConv" : "toFlag",
"MuCallConv" : "toCallConv",
"MuCommInst" : "toCommInst",
}
_special_return_converters = {
......@@ -216,7 +218,9 @@ def param_converter(pn, pt, rn, rt, is_optional, array_sz, is_out):
if pt in _primitive_types or pt in _no_conversion or is_out:
return rn # does not need conversion
if type_is_node(pt):
if type_is_node(pt) or pt == "MuID":
if is_optional:
return "readMuIDOptional({})".format(rn)
return rn # does not need conversion
if array_sz is not None:
......@@ -238,7 +242,10 @@ def param_converter(pn, pt, rn, rt, is_optional, array_sz, is_out):
return "getMuValueNotNull({}).asInstanceOf[{}]".format(rn, pt)
if pt in _special_converters:
return "{}({})".format(_special_converters[pt], rn)
converter = _special_converters[pt]
if is_optional:
converter = converter + "Optional"
return "{}({})".format(converter, rn)
raise ValueError("I don't know how to convert {}. Param name: {}".format(
pt, pn))
......
python3 muapitocstubs.py
python3 muapitoirbuildercomminstsimpl.py
python3 muapitolibmupy.py
python3 irbuildernodestoirbuildermethods.py
......@@ -9,6 +9,7 @@ import uvm.types._
import uvm.utils.IDFactory
import uvm.staticanalysis.InstructionResultInferer
import scala.collection.mutable.HashMap
import uvm.comminsts.CommInst
object IRBuilder {
......@@ -194,7 +195,7 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
val _node = new NodeFunc(id, sig)
onNewNodeCreated(_node)
}
def newExpFunc(id: MuID, func: MuFuncNode, callconv: MuCallConv, cookie: MuConstIntNode): Unit = {
def newExpFunc(id: MuID, func: MuFuncNode, callconv: Flag, cookie: MuConstIntNode): Unit = {
val _node = new NodeExpFunc(id, func, callconv, cookie)
onNewNodeCreated(_node)
}
......@@ -214,8 +215,8 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
val _node = new NodeExcClause(id, nor, exc)
onNewNodeCreated(_node)
}
def newKeepAliveClasue(id: MuID, vars: Seq[MuLocalVarNode]): Unit = {
val _node = new NodeKeepAliveClasue(id, vars)
def newKeepaliveClause(id: MuID, vars: Seq[MuLocalVarNode]): Unit = {
val _node = new NodeKeepaliveClause(id, vars)
onNewNodeCreated(_node)
}
def newCscRetWith(id: MuID, rettys: Seq[MuVarNode]): Unit = {
......@@ -234,15 +235,15 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
val _node = new NodeNscThrowExc(id, exc)
onNewNodeCreated(_node)
}
def newBinOp(id: MuID, resultID: MuID, optr: MuBinOptr, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode, excClaues: Option[MuExcClause]): Unit = {
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)
onNewNodeCreated(_node)
}
def newCmp(id: MuID, resultID: MuID, optr: MuBinOptr, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode): Unit = {
def newCmp(id: MuID, resultID: MuID, optr: CmpOptr.Value, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode): Unit = {
val _node = new NodeCmp(id, resultID, optr, ty, opnd1, opnd2)
onNewNodeCreated(_node)
}
def newConv(id: MuID, resultID: MuID, optr: MuBinOptr, fromTy: MuTypeNode, toTy: MuTypeNode, opnd: MuVarNode): Unit = {
def newConv(id: MuID, resultID: MuID, optr: ConvOptr.Value, fromTy: MuTypeNode, toTy: MuTypeNode, opnd: MuVarNode): Unit = {
val _node = new NodeConv(id, resultID, optr, fromTy, toTy, opnd)
onNewNodeCreated(_node)
}
......@@ -334,23 +335,23 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
val _node = new NodeGetVarPartIRef(id, resultID, isPtr, refty, opnd)
onNewNodeCreated(_node)
}
def newLoad(id: MuID, resultID: MuID, isPtr: Boolean, ord: MuMemOrd, refty: MuTypeNode, loc: MuVarNode, excClause: Option[MuExcClause]): Unit = {
def newLoad(id: MuID, resultID: MuID, isPtr: Boolean, ord: MemoryOrder.Value, refty: MuTypeNode, loc: MuVarNode, excClause: Option[MuExcClause]): Unit = {
val _node = new NodeLoad(id, resultID, isPtr, ord, refty, loc, excClause)
onNewNodeCreated(_node)
}
def newStore(id: MuID, isPtr: Boolean, ord: MuMemOrd, refty: MuTypeNode, loc: MuVarNode, newval: MuVarNode, excClause: Option[MuExcClause]): Unit = {
def newStore(id: MuID, isPtr: Boolean, ord: MemoryOrder.Value, refty: MuTypeNode, loc: MuVarNode, newval: MuVarNode, excClause: Option[MuExcClause]): Unit = {
val _node = new NodeStore(id, isPtr, ord, refty, loc, newval, excClause)
onNewNodeCreated(_node)
}
def newCmpXchg(id: MuID, valueResultID: MuID, succResultID: MuID, isPtr: Boolean, isWeak: Boolean, ordSucc: MuMemOrd, ordFail: MuMemOrd, refty: MuTypeNode, loc: MuVarNode, expected: MuVarNode, desired: MuVarNode, excClause: Option[MuExcClause]): Unit = {
def newCmpXchg(id: MuID, valueResultID: MuID, succResultID: MuID, isPtr: Boolean, isWeak: Boolean, ordSucc: MemoryOrder.Value, ordFail: MemoryOrder.Value, refty: MuTypeNode, loc: MuVarNode, expected: MuVarNode, desired: MuVarNode, excClause: Option[MuExcClause]): Unit = {
val _node = new NodeCmpXchg(id, valueResultID, succResultID, isPtr, isWeak, ordSucc, ordFail, refty, loc, expected, desired, excClause)
onNewNodeCreated(_node)
}
def newAtomicRMW(id: MuID, resultID: MuID, isPtr: Boolean, ord: MuMemOrd, optr: MuAtomicRMWOptr, refTy: MuTypeNode, loc: MuVarNode, opnd: MuVarNode, excClause: Option[MuExcClause]): Unit = {
def newAtomicRMW(id: MuID, resultID: MuID, isPtr: Boolean, ord: MemoryOrder.Value, optr: AtomicRMWOptr.Value, refTy: MuTypeNode, loc: MuVarNode, opnd: MuVarNode, excClause: Option[MuExcClause]): Unit = {
val _node = new NodeAtomicRMW(id, resultID, isPtr, ord, optr, refTy, loc, opnd, excClause)
onNewNodeCreated(_node)
}
def newFence(id: MuID, ord: MuMemOrd): Unit = {
def newFence(id: MuID, ord: MemoryOrder.Value): Unit = {
val _node = new NodeFence(id, ord)
onNewNodeCreated(_node)
}
......@@ -366,7 +367,7 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
val _node = new NodeWPBranch(id, wpid)
onNewNodeCreated(_node)
}
def newCCall(id: MuID, resultIds: Seq[MuID], callconv: MuCallConv, calleeTy: MuTypeNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
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)
}
......@@ -378,7 +379,7 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
val _node = new NodeSwapStack(id, resultIds, swappee, curStackClause, newStackClause, excClause, keepaliveClause)
onNewNodeCreated(_node)
}
def newCommInst(id: MuID, resultIds: Seq[MuID], opcode: MuCommInst, flags: Seq[MuFlag], tys: Seq[MuTypeNode], sigs: Seq[MuFuncSigNode], args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]): Unit = {
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)
}
......
......@@ -21,18 +21,20 @@ object IRBuilderNode {
type MuNewStackClause = MuID
type MuWPID = MuID
type MuFlag = Int
type MuBinOptr = MuFlag
type MuCmpOptr = MuFlag
type MuConvOptr = MuFlag
type MuMemOrd = MuFlag
type MuAtomicRMWOptr = MuFlag
type MuCallConv = MuFlag
type MuCommInst = MuFlag
//type MuBinOptr = MuFlag
//type MuCmpOptr = MuFlag
//type MuConvOptr = MuFlag
//type MuMemOrd = MuFlag
//type MuAtomicRMWOptr = MuFlag
//type MuCallConv = MuFlag
//type MuCommInst = MuFlag
}
import IRBuilderNode._
import uvm.ssavariables._
import uvm.comminsts.CommInst
abstract class IRBuilderNode(val id: MuID)
abstract class IRBuilderNode(id: MuID)
// EXT:BEGIN:IRBUILDER_NODES
......@@ -76,7 +78,7 @@ case class NodeGlobalCell(id: MuID, ty: MuTypeNode) extends IRBuilderNode(id)
case class NodeFunc(id: MuID, sig: MuFuncSigNode) extends IRBuilderNode(id)
case class NodeExpFunc(id: MuID, func: MuFuncNode, callconv: MuCallConv, cookie: MuConstIntNode) extends IRBuilderNode(id)
case class NodeExpFunc(id: MuID, func: MuFuncNode, callconv: Flag, cookie: MuConstIntNode) extends IRBuilderNode(id)
case class NodeFuncVer(id: MuID, func: MuFuncNode, bbs: Seq[MuBBNode]) extends IRBuilderNode(id)
......@@ -85,7 +87,7 @@ case class NodeDestClause(id: MuID, dest: MuBBNode, vars: Seq[MuVarNode]) extend
case class NodeExcClause(id: MuID, nor: MuDestClause, exc: MuDestClause) extends IRBuilderNode(id)
case class NodeKeepAliveClasue(id: MuID, vars: Seq[MuLocalVarNode]) extends IRBuilderNode(id)
case class NodeKeepaliveClause(id: MuID, vars: Seq[MuLocalVarNode]) extends IRBuilderNode(id)
case class NodeCscRetWith(id: MuID, rettys: Seq[MuVarNode]) extends IRBuilderNode(id)
case class NodeCscKillOld(id: MuID) extends IRBuilderNode(id)
......@@ -93,9 +95,9 @@ case class NodeCscKillOld(id: MuID) extends IRBuilderNode(id)
case class NodeNscPassValues(id: MuID, tys: Seq[MuTypeNode], vars: Seq[MuVarNode]) extends IRBuilderNode(id)
case class NodeNscThrowExc(id: MuID, exc: MuVarNode) extends IRBuilderNode(id)
case class NodeBinOp(id: MuID, resultID: MuID, optr: MuBinOptr, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode, excClaues: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeCmp(id: MuID, resultID: MuID, optr: MuBinOptr, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode) extends IRBuilderNode(id)
case class NodeConv(id: MuID, resultID: MuID, optr: MuBinOptr, fromTy: MuTypeNode, toTy: MuTypeNode, opnd: MuVarNode) extends IRBuilderNode(id)
case class NodeBinOp(id: MuID, resultID: MuID, optr: BinOptr.Value, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode, excClaues: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeCmp(id: MuID, resultID: MuID, optr: CmpOptr.Value, ty: MuTypeNode, opnd1: MuVarNode, opnd2: MuVarNode) extends IRBuilderNode(id)
case class NodeConv(id: MuID, resultID: MuID, optr: ConvOptr.Value, fromTy: MuTypeNode, toTy: MuTypeNode, opnd: MuVarNode) extends IRBuilderNode(id)
case class NodeSelect(id: MuID, resultID: MuID, condTy: MuTypeNode, opndTy: MuTypeNode, cond: MuVarNode, ifTrue: MuVarNode, ifFalse: MuVarNode) extends IRBuilderNode(id)
case class NodeBranch(id: MuID, dest: MuDestClause) extends IRBuilderNode(id)
......@@ -119,17 +121,17 @@ case class NodeGetFieldIRef(id: MuID, resultID: MuID, isPtr: Boolean, refty: MuT
case class NodeGetElemIRef(id: MuID, resultID: MuID, isPtr: Boolean, refty: MuTypeNode, indty: MuTypeNode, opnd: MuVarNode, index: MuVarNode) extends IRBuilderNode(id)
case class NodeShiftIRef(id: MuID, resultID: MuID, isPtr: Boolean, refty: MuTypeNode, offty: MuTypeNode, opnd: MuVarNode, offset: MuVarNode) extends IRBuilderNode(id)
case class NodeGetVarPartIRef(id: MuID, resultID: MuID, isPtr: Boolean, refty: MuTypeNode, opnd: MuVarNode) extends IRBuilderNode(id)
case class NodeLoad(id: MuID, resultID: MuID, isPtr: Boolean, ord: MuMemOrd, refty: MuTypeNode, loc: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeStore(id: MuID, isPtr: Boolean, ord: MuMemOrd, refty: MuTypeNode, loc: MuVarNode, newval: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeCmpXchg(id: MuID, valueResultID: MuID, succResultID: MuID, isPtr: Boolean, isWeak: Boolean, ordSucc: MuMemOrd, ordFail: MuMemOrd, refty: MuTypeNode, loc: MuVarNode, expected: MuVarNode, desired: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeAtomicRMW(id: MuID, resultID: MuID, isPtr: Boolean, ord: MuMemOrd, optr: MuAtomicRMWOptr, refTy: MuTypeNode, loc: MuVarNode, opnd: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeFence(id: MuID, ord: MuMemOrd) extends IRBuilderNode(id)
case class NodeLoad(id: MuID, resultID: MuID, isPtr: Boolean, ord: MemoryOrder.Value, refty: MuTypeNode, loc: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeStore(id: MuID, isPtr: Boolean, ord: MemoryOrder.Value, refty: MuTypeNode, loc: MuVarNode, newval: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeCmpXchg(id: MuID, valueResultID: MuID, succResultID: MuID, isPtr: Boolean, isWeak: Boolean, ordSucc: MemoryOrder.Value, ordFail: MemoryOrder.Value, refty: MuTypeNode, loc: MuVarNode, expected: MuVarNode, desired: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeAtomicRMW(id: MuID, resultID: MuID, isPtr: Boolean, ord: MemoryOrder.Value, optr: AtomicRMWOptr.Value, refTy: MuTypeNode, loc: MuVarNode, opnd: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeFence(id: MuID, ord: MemoryOrder.Value) extends IRBuilderNode(id)
case class NodeTrap(id: MuID, resultIds: Seq[MuID], rettys: Seq[MuTypeNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]) extends IRBuilderNode(id)
case class NodeWatchPoint(id: MuID, wpid: MuWPID, resultIds: Seq[MuID], rettys: Seq[MuTypeNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]) extends IRBuilderNode(id)
case class NodeWPBranch(id: MuID, wpid: MuWPID) extends IRBuilderNode(id)
case class NodeCCall(id: MuID, resultIds: Seq[MuID], callconv: MuCallConv, calleeTy: MuTypeNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]) extends IRBuilderNode(id)
case class NodeCCall(id: MuID, resultIds: Seq[MuID], callconv: Flag, calleeTy: MuTypeNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]) extends IRBuilderNode(id)
case class NodeNewThread(id: MuID, resultID: MuID, stack: MuVarNode, threadlocal: Option[MuVarNode], newStackClause: MuNewStackClause, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeSwapStack(id: MuID, resultIds: Seq[MuID], swappee: MuVarNode, curStackClause: MuCurStackClause, newStackClause: MuNewStackClause, excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]) extends IRBuilderNode(id)
case class NodeCommInst(id: MuID, resultIds: Seq[MuID], opcode: MuCommInst, flags: Seq[MuFlag], tys: Seq[MuTypeNode], sigs: Seq[MuFuncSigNode], args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]) extends IRBuilderNode(id)
case class NodeCommInst(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]) extends IRBuilderNode(id)
// EXT:END:IRBUILDER_NODES
\ No newline at end of file
This diff is collapsed.
......@@ -17,6 +17,8 @@ import uvm.TrantientBundle
import uvm.types.Type
import uvm.ssavariables.Constant
import uvm.ir.irbuilder.IRBuilder
import uvm.comminsts.CommInst
import uvm.comminsts.CommInsts
class ExposedMethod(name: String, jRetTy: JType, jParamTys: Array[JType], invokeFunc: Buffer => Unit) {
val closure = new SimpleClosure(name, invokeFunc)
......@@ -42,6 +44,10 @@ private object CDefsHelperFunctions {
def exposedMethod(name: String, jRetTy: JType, jParamTys: Array[JType])(invokeFunc: Buffer => Unit) = {
new ExposedMethod(name: String, jRetTy, jParamTys, invokeFunc)
}
def readMuIDOptional(id: MuID): Option[MuID] = {
if (id == 0) None else Some(id)
}
def readIntArray(base: Long, len: Long): IndexedSeq[Int] = {
if (base == 0L) {
......@@ -66,22 +72,27 @@ private object CDefsHelperFunctions {
}
}
}
def readMuIDArray(base: Long, len: Long): IndexedSeq[MuID] = readIntArray(base, len)
def readMuValueArray(base: Long, len: Long): IndexedSeq[MuValue] = {
readLongArray(base, len).map(getMuValueNotNull)
}
def readFlagArray(base: Long, len: Long): IndexedSeq[Flag] = {
readIntArray(base, len).map(toFlag)
readIntArray(base, len).map(toCallConv)
}
def intToBoolean(v: Int): Boolean = v != 0
def booleanToInt(v: Boolean): Int = if (v) 1 else 0
def toFlag(cval: Int): Flag = cval match {
def toMuFlag(cc: Int): MuFlag = cc
def toCallConv(cc: Int): Flag = cc match {
case 0x00 => Flag("#DEFAULT")
case _ => throw new IllegalArgumentException("Unknown calling convention %d (0x%x)".format(cval, cval))
case _ => throw new IllegalArgumentException("Unknown calling convention %d (0x%x)".format(cc, cc))
}
def toCommInst(ci: Int): CommInst = CommInsts(ci)
val MAX_NAME_SIZE = 65536
......@@ -89,6 +100,10 @@ private object CDefsHelperFunctions {
val str = theMemory.getString(addr, MAX_NAME_SIZE, StandardCharsets.US_ASCII)
str
}
def readCStringOptional(addr: Long): Option[String] = {
if (addr == 0L) None else Some(readCString(addr))
}
def readCharArray(base: Long, len: Long): String = {
require(len <= Int.MaxValue, "Currently Mu refimpl2 only supports string length with 32-bit range")
......@@ -162,10 +177,12 @@ private object CDefsHelperFunctions {
theMemory.putAddress(addr, fak)
}
}
def newConstIntEx(b: IRBuilder, id: MuID, ty: MuID, values: Seq[Long]): Unit = {
}
implicit class RichMuIRBuilder(val b: IRBuilder) extends AnyVal {
def newConstIntEx(id: MuID, ty: MuID, values: Seq[Long]): Unit = {
val bigNum = unsignedLongSeqToBigInt(values)
b.newConstInt(b, id, ty, value)
b.newConstInt(id, ty, bigNum)
}
}
......
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