GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

Commit 8876d93c authored by Kunshan Wang's avatar Kunshan Wang

c interface

parent 5ac4d9fd
......@@ -122,9 +122,9 @@ typedef MuFlag MuDestKind;
#define MU_DEST_EXCEPT 0x02
#define MU_DEST_TRUE 0x03
#define MU_DEST_FALSE 0x04
#define MU_DEST_DEFAULT 0x04
#define MU_DEST_DISABLED 0x05
#define MU_DEST_ENABLED 0x06
#define MU_DEST_DEFAULT 0x05
#define MU_DEST_DISABLED 0x06
#define MU_DEST_ENABLED 0x07
// Binary operators
typedef MuFlag MuBinOptr;
......@@ -413,10 +413,10 @@ struct MuCtx {
MuChildNode (*get_node )(MuCtx *ctx, MuBundleNode b, MuID id);
// Get the ID of the IR node "node".
MuID (*get_id )(MuCtx *ctx, MuChildNode node);
MuID (*get_id )(MuCtx *ctx, MuBundleNode b, MuChildNode node);
// Set the name of the IR node. MuName is '\0' terminated char*.
void (*set_name )(MuCtx *ctx, MuChildNode node, MuName name);
void (*set_name )(MuCtx *ctx, MuBundleNode b, MuChildNode node, MuName name);
/// Create top-level definitions. When created, they are added to the bundle "b".
......@@ -463,9 +463,9 @@ struct MuCtx {
MuConstNode (*new_const_float )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, float value);
MuConstNode (*new_const_double )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, double value);
// new_const_null works for all general reference types, but not uptr or ufuncptr.
MuConstNode (*new_const_null )(MuCtx *ctx, MuBundleNode b);
MuConstNode (*new_const_null )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty);
// new_const_seq works for structs, arrays and vectors. Constants are non-recursive, so there is no populate_list_const.
MuConstNode (*new_const_seq )(MuCtx *ctx, MuBundleNode b, MuConstNode *elems, int nelems);
MuConstNode (*new_const_seq )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, MuConstNode *elems, int nelems);
// Create global cell
MuGlobalNode (*new_global_cell )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty);
......@@ -515,7 +515,7 @@ struct MuCtx {
MuInstNode (*new_branch )(MuCtx *ctx, MuBBNode bb);
MuInstNode (*new_branch2 )(MuCtx *ctx, MuBBNode bb, MuVarNode cond);
MuInstNode (*new_switch )(MuCtx *ctx, MuBBNode bb, MuVarNode opnd);
MuInstNode (*new_switch )(MuCtx *ctx, MuBBNode bb, MuTypeNode opnd_ty, MuVarNode opnd);
void (*add_switch_dest )(MuCtx *ctx, MuInstNode sw, MuConstNode key, MuBBNode dest, MuVarNode *vars, int nvars);
MuInstNode (*new_call )(MuCtx *ctx, MuBBNode bb, MuFuncSigNode sig, MuVarNode callee, MuVarNode *args, int nargs);
......@@ -543,7 +543,7 @@ struct MuCtx {
MuInstNode (*new_load )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuMemOrd ord, MuTypeNode refty, MuVarNode loc);
MuInstNode (*new_store )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuMemOrd ord, MuTypeNode refty, MuVarNode loc, MuVarNode newval);
MuInstNode (*new_cmpxchg )(MuCtx *ctx, MuBBNode bb, int is_ptr, int is_weak, MuMemOrd ord_succ, MuMemOrd ord_fail, MuTypeNode refty, MuVarNode loc, MuVarNode expected, MuVarNode desired);
MuInstNode (*new_atomicrmw )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuMemOrd ord, MuAtomicRMWOp optr, MuVarNode loc, MuVarNode opnd);
MuInstNode (*new_atomicrmw )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuMemOrd ord, MuAtomicRMWOp optr, MuTypeNode refTy, MuVarNode loc, MuVarNode opnd);
MuInstNode (*new_fence )(MuCtx *ctx, MuBBNode bb, MuMemOrd ord);
MuInstNode (*new_trap )(MuCtx *ctx, MuBBNode bb, MuTypeNode *rettys, int nrettys);
......@@ -553,10 +553,10 @@ struct MuCtx {
MuInstNode (*new_ccall )(MuCtx *ctx, MuBBNode bb, MuCallConv callconv, MuTypeNode callee_ty, MuFuncSigNode sig, MuVarNode callee, MuVarNode *args, int nargs);
MuInstNode (*new_newthread )(MuCtx *ctx, MuBBNode bb, MuVarNode stack, MuVarNode threadlocal);
MuInstNode (*new_swapstack_ret )(MuCtx *ctx, MuBBNode bb, MuVarNode swappee, MuTypeNode *tys, int ntys);
MuInstNode (*new_swapstack_ret )(MuCtx *ctx, MuBBNode bb, MuVarNode swappee, MuTypeNode *ret_tys, int nret_tys);
MuInstNode (*new_swapstack_kill)(MuCtx *ctx, MuBBNode bb, MuVarNode swappee);
void (*set_newstack_pass_values)(MuCtx *ctx, MuInstNode inst, MuTypeNode tys, MuVarNode *vars, int nvars);
void (*set_newstack_pass_values)(MuCtx *ctx, MuInstNode inst, MuTypeNode *tys, MuVarNode *vars, int nvars);
void (*set_newstack_throw_exc )(MuCtx *ctx, MuInstNode inst, MuVarNode exc);
MuInstNode (*new_comminst )(MuCtx *ctx, MuBBNode bb, MuCommInst opcode,
......
......@@ -2,6 +2,8 @@
USAGE: python3 migrate_scripts/irbuildertomuctx.py < src/main/scala/uvm/ir/irbuilder/IRBuilder.scala | xclip -selection c
And then paste the result into src/main/scala/uvm/refimpl/MuCtxIRBuilderPart.scala
Use pbcopy on Mac.
"""
import re
......
"""
Converts MuCtx methods in muapi.h to nativeClientSupport
USAGE: python3 muapitoncs.py < cbinding/muapi.h | xclip -selection c
then paste in function signatures, then paste the result in
src/main/scala/uvm/refimpl/nat/nativeClientSupport.scala
Use pbcopy on Mac.
"""
import sys
import re
r_comment = re.compile(r'//.*$', re.MULTILINE)
r_decl = re.compile(r'(?P<ret>\w+)\s*\(\s*\*\s*(?P<name>\w+)\s*\)\s*\((?P<params>[^)]*)\)\s*;')
r_param = re.compile(r'\s*(?P<type>\w+)\s*(?P<ptr>\*?)\s*(?P<name>\w+)')
r_value_ty = re.compile(r'Mu\w*(Value|Node)')
begin = "/// IR Builder API"
end = "// Common instruction opcodes"
lines = sys.stdin.read().splitlines()
l1 = [n for (n,l) in enumerate(lines) if begin in l][0]
l2 = [n for (n,l) in enumerate(lines) if end in l][0]
text = "\n".join(lines[l1+1:l2])
text = r_comment.sub("", text)
_simple_map = {
"void": "Unit",
"int": "Int",
"long": "Long",
"uint64_t": "Long",
"uint64_t*": "LongPtr",
"float": "Float",
"double": "Double",
}
def conv_ret_ty(ty):
if ty in _simple_map:
ty = _simple_map[ty]
m = r_value_ty.match(ty)
if m is not None:
return (True, "MuValueFak")
else:
return (False, ty)
_special_case = {
"id": "ID",
"uptr": "UPtr",
"ufuncptr": "UFuncPtr",
"iref": "IRef",
"weakref": "WeakRef",
"funcref": "FuncRef",
"tagref64": "TagRef64",
"threadref": "ThreadRef",
"stackref": "StackRef",
"framecursorref": "FrameCursorRef",
"irnoderef": "IRNodeRef",
"funcsig": "FuncSig",
"bb": "BB",
"keepalives": "KeepAlives",
"binop": "BinOp",
"tailcall": "TailCall",
"extractvalue": "ExtractValue",
"insertvalue" : "InsertValue",
"extractelement": "ExtractElement",
"insertelement" : "InsertElement",
"shufflevector" : "ShuffleVector",
"newhybrid" : "NewHybrid",
"allocahybrid" : "AllocaHybrid",
"getiref" : "GetIRef",
"getfieldiref" : "GetFieldIRef",
"getelemiref" : "GetElemIRef",
"shiftiref" : "ShiftIRef",
"getvarpartiref": "GetVarPartIRef",
"cmpxchg" : "CmpXchg",
"atomicrmw" : "AtomicRMW",
"watchpoint" : "WatchPoint",
"wpbranch" : "WPBranch",
"ccall" : "CCall",
"newthread" : "NewThread",
"newstack" : "NewStack",
"swapstack" : "SwapStack",
"comminst" : "CommInst",
}
def toCamelCase(name):
ins = name.split("_")
outs = [ins[0]]
for inn in ins[1:]:
if inn in _special_case:
outs.append(_special_case[inn])
else:
outs.append(inn[0].upper()+inn[1:])
return "".join(outs)
_special_param = {
}
def conv_param_ty(name, ty):
if ty == "MuCtx*":
return "MuCtx"
elif r_value_ty.match(ty) is not None and ty.endswith("*"):
return "MuValueFakArrayPtr"
elif ty == "MuFlag*":
return "MuFlagArrayPtr"
elif name == "threadlocal" and ty == "MuVarNode":
return "Option[MuVarNode]"
elif ty in _special_param:
return _special_param[ty]
elif ty in _simple_map:
return _simple_map[ty]
else:
return ty
def conv_param_val(func, name, ty):
if ty == "MuValueFakArrayPtr":
if func == "set_newstack_pass_values":
lenvar = "nvars"
else:
lenvar = "n" + name
return "readFromValueFakArray({}, {})".format(name, lenvar)
elif ty == "MuFlagArrayPtr":
lenvar = "n" + name
return "readFromFlagArray({}, {})".format(name, lenvar)
elif name in ["is_ptr", "is_weak"]:
return name + " != 0"
else:
return name
_num_params = "nfieldtys nfixedtys nparamtys nrettys nelems nargs nrvs nvars nflags ntys nsigs nret_tys".split()
def forward_call(func, params):
params = [p for p in params if p[0] not in _num_params]
return "ctx.{}({})".format(toCamelCase(func), ", ".join(
conv_param_val(func, n, t) for n,t in params))
for m in r_decl.finditer(text):
name, params, ret = [m.groupdict()[k] for k in "name params ret".split()]
params_out = []
params = params.split(",")
for param in params:
mp = r_param.search(param)
pt, pp, pn = [mp.groupdict()[k] for k in "type ptr name".split()]
pt = conv_param_ty(pn, pt+pp)
params_out.append((pn, pt))
params_out_str = ", ".join("{}: {}".format(pn, pt) for pn, pt in params_out)
is_value, ret = conv_ret_ty(ret)
impl = forward_call(name, params_out[1:])
if is_value:
impl = "exposeMuValue(ctx, {})".format(impl)
print(" def {}({}): {} = {}".format(name, params_out_str, ret, impl))
package uvm.ir.irbuilder
import scala.collection.mutable.ArrayBuffer
import uvm.utils.IDFactory
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.comminsts.CommInsts
import uvm.ssavariables._
import uvm.types._
import uvm.utils.IDFactory
object DestKind extends Enumeration {
val NORMAL, EXCEPT, TRUE, FALSE, DEFAULT, DISABLED, ENABLED = Value
......@@ -417,6 +418,11 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
newInst(bb, inst)
}
def newWPBranch(bb: CN[BB], wpid: Int): CN[InstWPBranch] = {
val inst = InstWPBranch(wpid, null, null)
newInst(bb, inst)
}
def newCCall(bb: CN[BB], callConv: Flag, calleeTy: CN[Type], sig: CN[FuncSig], callee: CN[Var], args: Seq[CN[Var]]): CN[InstCCall] = {
val inst = InstCCall(callConv, calleeTy, sig, callee, args, None, Seq())
newInst(bb, inst)
......@@ -439,8 +445,7 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
newInst(bb, inst)
}
def setNewStackPassValues(inst: CN[Instruction], tys: Seq[CN[Type]], vars: Seq[CN[Var]]): Unit = {
val newStackClause = PassValues(tys, vars)
private def setNewStackClause(inst: CN[Instruction], newStackClause: NewStackAction): Unit = {
inst.obj match {
case i: InstNewThread => i.newStackAction = newStackClause
case i: InstSwapStack => i.newStackAction = newStackClause
......@@ -450,6 +455,16 @@ class IRBuilder(globalBundle: GlobalBundle, idFactory: IDFactory) {
}
}
def setNewStackPassValues(inst: CN[Instruction], tys: Seq[CN[Type]], vars: Seq[CN[Var]]): Unit = {
val newStackClause = PassValues(tys, vars)
setNewStackClause(inst, newStackClause)
}
def setNewStackThrowExc(inst: CN[Instruction], exc: CN[Var]): Unit = {
val newStackClause = ThrowExc(exc)
setNewStackClause(inst, newStackClause)
}
def newCommInst(bb: CN[BB], opcode: Int, flags: Seq[Flag], tys: Seq[CN[Type]], sigs: Seq[CN[FuncSig]], args: Seq[CN[Var]]): CN[InstCommInst] = {
val commInst = CommInsts.get(opcode).getOrElse {
throw new IllegalArgumentException("No such common instruction. opcode: %d 0x%x".format(opcode, opcode))
......
......@@ -576,6 +576,11 @@ trait MuCtxIRBuilderPart {
addHandle(irBuilder.newWatchPoint(bb, wpid, retTys))
}
def newWPBranch(bb: MuBBNode, wpid: Int): MuInstNode = {
require(!bb.isNull, "bb must not be NULL")
addHandle(irBuilder.newWPBranch(bb, wpid))
}
def newCCall(bb: MuBBNode, callConv: Flag, calleeTy: MuTypeNode, sig: MuFuncSigNode, callee: MuVarNode, args: Seq[MuVarNode]): MuInstNode = {
require(!bb.isNull, "bb must not be NULL")
require(!calleeTy.isNull, "calleeTy must not be NULL")
......@@ -611,6 +616,12 @@ trait MuCtxIRBuilderPart {
irBuilder.setNewStackPassValues(inst, tys, vars)
}
def setNewStackThrowExc(inst: MuInstNode, exc: MuVarNode): Unit = {
require(!inst.isNull, "inst must not be NULL")
require(!exc.isNull, "exc must not be NULL")
irBuilder.setNewStackThrowExc(inst, exc)
}
def newCommInst(bb: MuBBNode, opcode: Int, flags: Seq[Flag], tys: Seq[MuTypeNode], sigs: Seq[MuFuncSigNode], args: Seq[MuVarNode]): MuInstNode = {
require(!bb.isNull, "bb must not be NULL")
for((n,i) <- tys.zipWithIndex) require(!n.isNull, "tys[%d] must not be NULL".format(i))
......
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