WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit de2867ae authored by Kunshan Wang's avatar Kunshan Wang
Browse files

internal IR builder nodes

parent 3884e361
""" This is for one-time use only. It generates contents of
uvm.ir.irbuilder/irBuilderNode.scala, but that file should be maintained
manually in the long run. """
import muapiparser
from refimpl2injectablefiles import muapi_h_path
from muapitocstubs import toCamelCase
_to_scala_type = {
"int": "Int",
"MuBool": "Boolean",
}
def to_scala_type(rt):
return _to_scala_type.get(rt, rt)
def generate_node(method):
func_name = toCamelCase(method["name"])
node_name = "Node" + func_name[3:]
params = method["params"][1:] # skip MuIRBuilder*
node_params = []
for param in params:
pn = param['name']
pt = param['type']
nn = toCamelCase(pn)
if param.get("is_sz_param", False):
continue
elif 'array_sz_param' in param:
assert pt.endswith("*")
rt = pt[:-1]
st = to_scala_type(rt)
nt = "Seq[{}]".format(pt[:-1])
elif param.get('is_optional', False):
assert pt in ["MuCString", "MuID"] or pt.endswith("*") or any(
pt.endswith(x) for x in ["Clause", "Node"]), pt
if pt.endswith("*"):
rt = pt[:-1]
else:
rt = pt
st = to_scala_type(rt)
nt = "Option[{}]".format(rt)
else:
rt = pt
st = to_scala_type(rt)
nt = st
node_params.append((nn, nt))
return '''case class {}({}) extends IRBuilderNode(id)'''.format(
node_name, ", ".join("{}: {}".format(nn, nt) for (nn, nt) in node_params))
def generate_things(ast):
irb = [s for s in ast["structs"] if s["name"] == "MuIRBuilder"][0]
nodes = []
for meth in irb["methods"]:
if meth["name"].startswith("new_"):
nodes.append(generate_node(meth))
return "\n".join(nodes)
def main():
with open(muapi_h_path) as f:
src_text = f.read()
ast = muapiparser.parse_muapi(src_text)
generated = generate_things(ast)
print(generated)
if __name__=='__main__':
main()
......@@ -35,7 +35,7 @@ def find_line(lines: List[str], substr: Predicate, start: int = 0) -> int:
if pred(lines[i], substr):
return i
raise KeyError("Not found: " + str(substr) + "\n text:" + str(lines) )
raise Exception("Not found: " + str(substr) + "\n text:" + str(lines) )
def extract_lines(parent: str, begin: Predicate, end: Predicate) -> str:
"""
......
"""
Usage: python3 irbuildernodestoirbuildermethods.py
"""
import re
import sys, os.path, io
import injecttools
from refimpl2injectablefiles import injectable_files, irbuilder_nodes_path
replaces = [(re.compile(x), y) for (x,y) in [
(r'TrantientBundle', 'MuBundleNode'),
(r'TB', 'MuBundleNode'),
(r'Bundle', 'MuBundleNode'),
(r'TopLevel', 'MuChildNode'),
(r'ChildNode', 'MuChildNode'),
(r'Type\w*', 'MuTypeNode'),
(r'Abstract\w+Type', 'MuTypeNode'),
(r'FuncSig', 'MuFuncSigNode'),
(r'Const\w+', 'MuConstNode'),
(r'GlobalCell', 'MuGlobalNode'),
(r'Function', 'MuFuncNode'),
(r'ExposedFunc', 'MuExpFuncNode'),
(r'FuncVer', 'MuFuncVerNode'),
(r'BasicBlock', 'MuBBNode'),
(r'BB', 'MuBBNode'),
(r'SSAVariable', 'MuVarNode'),
(r'Var', 'MuVarNode'),
(r'LocalVariable', 'MuLocalVarNode'),
(r'NorParam', 'MuNorParamNode'),
(r'ExcParam', 'MuExcParamNode'),
(r'InstResult', 'MuInstResNode'),
(r'Inst\w+', 'MuInstNode'),
(r'HasKeepaliveClause', 'MuInstNode'),
]]
case_class_r = re.compile(r'^(case\s+class\s+(\w+)\s*\(([^)]*)\))', re.MULTILINE)
arg = re.compile(r'(\w+):\s*([a-zA-Z0-9\[\].]+)')
begin="EXT:BEGIN:IRBUILDER_NODES"
end="EXT:END:IRBUILDER_NODES"
def main():
with open(irbuilder_nodes_path) as f:
lines = f.read()
text = injecttools.extract_lines(lines, begin, end)
output = io.StringIO()
for whole, name, arglist in case_class_r.findall(text):
node_name = name
func_name = "new" + name[4:]
argnames = []
argtypes = []
for an,at in arg.findall(arglist):
argnames.append(an)
argtypes.append(at)
print(" def {}({}): Unit = {{".format(func_name, ", ".join(
"{}: {}".format(an, at) for an, at in zip(argnames, argtypes))),
file=output)
print(" val _node = new {}({})".format(node_name,
", ".join(argnames)), file=output)
print(" onNewNodeCreated(_node)", file=output)
print(" }", file=output)
#print(output.getvalue())
#return
injectable_files["IRBuilder.scala"].inject_many({
"IRBUILDERNODE_CONSTRUCTORS": output.getvalue(),
})
if __name__=='__main__':
main()
"""
USAGE: python3 migrate_scripts/irbuildertomuctx.py
And then paste the result intoUse pbcopy on Mac.
IRBuilder is no longer part of MuCtx. Don't use this.
"""
import re
......
......@@ -429,4 +429,5 @@ def main():
"STUBS": generated,
})
main()
if __name__=='__main__':
main()
......@@ -300,4 +300,5 @@ def main():
"MuCtx": muctx_stubs,
})
main()
if __name__=='__main__':
main()
......@@ -8,7 +8,8 @@ def _make_injectable_file_set(m):
m2 = {os.path.join(_refimpl2_root, k): v for k,v in m.items()}
return InjectableFileSet(m2)
muapi_h_path = os.path.join(_my_dir, "../cbinding/muapi.h")
muapi_h_path = os.path.join(_refimpl2_root, "cbinding/muapi.h")
irbuilder_nodes_path = os.path.join(_refimpl2_root, "src/main/scala/uvm/ir/irbuilder/irBuilderNodes.scala")
injectable_files = injecttools.make_injectable_file_set(_refimpl2_root, [
("cStubs.scala", "src/main/scala/uvm/refimpl/nat/cStubs.scala",
......@@ -25,4 +26,6 @@ injectable_files = injecttools.make_injectable_file_set(_refimpl2_root, [
["IRBUILDER_IMPL"]),
("MuCtxIRBuilderPart.scala", "src/main/scala/uvm/refimpl/MuCtxIRBuilderPart.scala",
["METHODS"]),
("IRBuilder.scala", "src/main/scala/uvm/ir/irbuilder/IRBuilder.scala",
["IRBUILDERNODE_CONSTRUCTORS"]),
])
python3 irbuildertomuctx.py
python3 muapitocstubs.py
python3 muapitoirbuildercomminstsimpl.py
python3 muapitolibmupy.py
package uvm.ir.irbuilder
import uvm.MuID
object IRBuilderNode {
type MuTypeNode = MuID
type MuFuncSigNode = MuID
type MuVarNode = MuID
type MuGlobalVarNode = MuID
type MuLocalVarNode = MuID
type MuConstNode = MuID
type MuConstIntNode = MuID
type MuFuncNode = MuID
type MuFuncVerNode = MuID
type MuBBNode = MuID
type MuInstNode = MuID
type MuDestClause = MuID
type MuExcClause = MuID
type MuKeepaliveClause = MuID
type MuCurStackClause = MuID
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
}
import IRBuilderNode._
abstract class IRBuilderNode(val id: MuID)
// EXT:BEGIN:IRBUILDER_NODES
// format: OFF
case class NodeTypeInt (id: MuID, len: Int) extends IRBuilderNode(id)
case class NodeTypeFloat (id: MuID) extends IRBuilderNode(id)
case class NodeTypeDouble (id: MuID) extends IRBuilderNode(id)
case class NodeTypeUPtr (id: MuID, ty: MuTypeNode) extends IRBuilderNode(id)
case class NodeTypeUFuncPtr(id: MuID, sig: MuFuncSigNode) extends IRBuilderNode(id)
case class NodeTypeStruct(id: MuID, fieldTys: Seq[MuTypeNode]) extends IRBuilderNode(id)
case class NodeTypeHybrid(id: MuID, fixedTys: Seq[MuTypeNode], varTy: MuTypeNode) extends IRBuilderNode(id)
case class NodeTypeArray (id: MuID, elemTy: MuTypeNode, len: Long) extends IRBuilderNode(id)
case class NodeTypeVector(id: MuID, elemTy: MuTypeNode, len: Long) extends IRBuilderNode(id)
case class NodeTypeVoid (id: MuID) extends IRBuilderNode(id)
case class NodeTypeRef (id: MuID, ty: MuTypeNode) extends IRBuilderNode(id)
case class NodeTypeIRef (id: MuID, ty: MuTypeNode) extends IRBuilderNode(id)
case class NodeTypeWeakRef(id: MuID, ty: MuTypeNode) extends IRBuilderNode(id)
case class NodeTypeFuncRef(id: MuID, sig: MuFuncSigNode) extends IRBuilderNode(id)
case class NodeTypeTagRef64 (id: MuID) extends IRBuilderNode(id)
case class NodeTypeThreadRef (id: MuID) extends IRBuilderNode(id)
case class NodeTypeStackRef (id: MuID) extends IRBuilderNode(id)
case class NodeTypeFrameCursorRef(id: MuID) extends IRBuilderNode(id)
case class NodeTypeIRBuilderRef (id: MuID) extends IRBuilderNode(id)
// format: ON
case class NodeFuncSig(id: MuID, paramTys: Seq[MuTypeNode], retTys: Seq[MuTypeNode]) extends IRBuilderNode(id)
// format: OFF
case class NodeConstInt (id: MuID, ty: MuTypeNode, value: BigInt) extends IRBuilderNode(id)
case class NodeConstFloat (id: MuID, ty: MuTypeNode, value: Float) extends IRBuilderNode(id)
case class NodeConstDouble(id: MuID, ty: MuTypeNode, value: Double) extends IRBuilderNode(id)
case class NodeConstNull (id: MuID, ty: MuTypeNode) extends IRBuilderNode(id)
case class NodeConstSeq (id: MuID, ty: MuTypeNode, elems: Seq[MuGlobalVarNode]) extends IRBuilderNode(id)
case class NodeConstExtern(id: MuID, ty: MuTypeNode, symbol: String) extends IRBuilderNode(id)
// format: ON
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 NodeFuncVer(id: MuID, func: MuFuncNode, bbs: Seq[MuBBNode]) extends IRBuilderNode(id)
case class NodeBB(id: MuID, norParamIDs: Seq[MuID], excParamID: Option[MuID], insts: Seq[MuInstNode]) extends IRBuilderNode(id)
case class NodeDestClause(id: MuID, dest: MuBBNode, vars: Seq[MuVarNode]) extends IRBuilderNode(id)
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 NodeCscRetWith(id: MuID, rettys: Seq[MuVarNode]) extends IRBuilderNode(id)
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 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)
case class NodeBranch2(id: MuID, cond: MuVarNode, ifTrue: MuDestClause, ifFalse: MuDestClause) extends IRBuilderNode(id)
case class NodeSwitch(id: MuID, opndTy: MuTypeNode, opnd: MuVarNode, defaultDest: MuDestClause, cases: Seq[MuConstNode], dests: Seq[MuDestClause]) extends IRBuilderNode(id)
case class NodeCall(id: MuID, resultIds: Seq[MuID], sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode], excClause: Option[MuExcClause], keepaliveClause: Option[MuKeepaliveClause]) extends IRBuilderNode(id)
case class NodeTailCall(id: MuID, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode]) extends IRBuilderNode(id)
case class NodeRet(id: MuID, rvs: Seq[MuVarNode]) extends IRBuilderNode(id)
case class NodeThrow(id: MuID, exc: MuVarNode) extends IRBuilderNode(id)
case class NodeExtractValue(id: MuID, resultID: MuID, strty: MuTypeNode, index: Int, opnd: MuVarNode) extends IRBuilderNode(id)
case class NodeInsertValue(id: MuID, resultID: MuID, strty: MuTypeNode, index: Int, opnd: MuVarNode, newval: MuVarNode) extends IRBuilderNode(id)
case class NodeExtractElement(id: MuID, resultID: MuID, seqty: MuTypeNode, indty: MuTypeNode, opnd: MuVarNode, index: MuVarNode) extends IRBuilderNode(id)
case class NodeInsertElement(id: MuID, resultID: MuID, seqty: MuTypeNode, indty: MuTypeNode, opnd: MuVarNode, index: MuVarNode, newval: MuVarNode) extends IRBuilderNode(id)
case class NodeShuffleVector(id: MuID, resultID: MuID, vecty: MuTypeNode, maskty: MuTypeNode, vec1: MuVarNode, vec2: MuVarNode, mask: MuVarNode) extends IRBuilderNode(id)
case class NodeNew(id: MuID, resultID: MuID, allocty: MuTypeNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeNewHybrid(id: MuID, resultID: MuID, allocty: MuTypeNode, lenty: MuTypeNode, length: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeAlloca(id: MuID, resultID: MuID, allocty: MuTypeNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeAllocaHybrid(id: MuID, resultID: MuID, allocty: MuTypeNode, lenty: MuTypeNode, length: MuVarNode, excClause: Option[MuExcClause]) extends IRBuilderNode(id)
case class NodeGetIRef(id: MuID, resultID: MuID, refty: MuTypeNode, opnd: MuVarNode) extends IRBuilderNode(id)
case class NodeGetFieldIRef(id: MuID, resultID: MuID, isPtr: Boolean, refty: MuTypeNode, index: Int, opnd: MuVarNode) extends IRBuilderNode(id)
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 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 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)
// EXT:END:IRBUILDER_NODES
\ No newline at end of file
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