GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit df5db6cc authored by Kunshan Wang's avatar Kunshan Wang

muapi.h parser

parent c225bf8a
......@@ -82,12 +82,8 @@ typedef uint32_t MuFlag;
// Result of a trap handler
typedef MuFlag MuTrapHandlerResult;
// Used by new_thread
typedef MuFlag MuHowToResume;
// Values or MuTrapHandlerResult
#define MU_THREAD_EXIT 0x00
// Values or MuTrapHandlerResult and muHowToResume
#define MU_REBIND_PASS_VALUES 0x01
#define MU_REBIND_THROW_EXC 0x02
......@@ -264,8 +260,8 @@ struct MuCtx {
void (*close_context)(MuCtx *ctx);
// Load bundles and HAIL scripts
void (*load_bundle)(MuCtx *ctx, char *buf, int sz);
void (*load_hail )(MuCtx *ctx, char *buf, int sz);
void (*load_bundle)(MuCtx *ctx, char *buf, int sz); /// MUAPIPARSER buf:array:sz
void (*load_hail )(MuCtx *ctx, char *buf, int sz); /// MUAPIPARSER buf:array:sz
// Convert from C values to Mu values
MuIntValue (*handle_from_sint8 )(MuCtx *ctx, int8_t num, int len);
......@@ -276,6 +272,7 @@ struct MuCtx {
MuIntValue (*handle_from_uint32)(MuCtx *ctx, uint32_t num, int len);
MuIntValue (*handle_from_sint64)(MuCtx *ctx, int64_t num, int len);
MuIntValue (*handle_from_uint64)(MuCtx *ctx, uint64_t num, int len);
MuIntValue (*handle_from_uint64s)(MuCtx *ctx, uint64_t *nums, int nnums, int len); /// MUAPIPARSER num:array:nnum
MuFloatValue (*handle_from_float )(MuCtx *ctx, float num);
MuDoubleValue (*handle_from_double)(MuCtx *ctx, double num);
MuUPtrValue (*handle_from_ptr )(MuCtx *ctx, MuID mu_type, MuCPtr ptr);
......@@ -307,9 +304,9 @@ struct MuCtx {
// Compare reference or general reference types.
// EQ. Available for ref, iref, funcref, threadref and stackref.
int (*ref_eq )(MuCtx *ctx, MuGenRefValue lhs, MuGenRefValue rhs);
int (*ref_eq )(MuCtx *ctx, MuGenRefValue lhs, MuGenRefValue rhs); /// MUAPIPARSER RV:bool
// ULT. Available for iref only.
int (*ref_ult)(MuCtx *ctx, MuIRefValue lhs, MuIRefValue rhs);
int (*ref_ult)(MuCtx *ctx, MuIRefValue lhs, MuIRefValue rhs); /// MUAPIPARSER RV:bool
// Manipulate Mu values of the struct<...> type
MuValue (*extract_value)(MuCtx *ctx, MuStructValue str, int index);
......@@ -339,17 +336,19 @@ struct MuCtx {
void (*store )(MuCtx *ctx, MuMemOrd ord, MuIRefValue loc, MuValue newval);
MuValue (*cmpxchg )(MuCtx *ctx, MuMemOrd ord_succ, MuMemOrd ord_fail,
int weak, MuIRefValue loc, MuValue expected, MuValue desired,
int *is_succ);
int *is_succ); /// MUAPIPARSER weak:bool
MuValue (*atomicrmw)(MuCtx *ctx, MuMemOrd ord, MuAtomicRMWOp op,
MuIRefValue loc, MuValue opnd);
void (*fence )(MuCtx *ctx, MuMemOrd ord);
// Thread and stack creation and stack destruction
MuStackRefValue (*new_stack )(MuCtx *ctx, MuFuncRefValue func);
MuThreadRefValue (*new_thread)(MuCtx *ctx, MuStackRefValue stack,
MuThreadRefValue (*new_thread_nor)(MuCtx *ctx, MuStackRefValue stack,
MuRefValue threadlocal,
MuValue *vals, int nvals); /// MUAPIPARSER threadlocal:optional;vals:array:nvals
MuThreadRefValue (*new_thread_exc)(MuCtx *ctx, MuStackRefValue stack,
MuRefValue threadlocal,
MuHowToResume htr, MuValue *vals, int nvals,
MuRefValue exc);
MuRefValue exc); /// MUAPIPARSER threadlocal:optional;exc:optional
void (*kill_stack)(MuCtx *ctx, MuStackRefValue stack);
// Thread-local object reference
......@@ -430,7 +429,9 @@ struct MuCtx {
void (*set_type_ufuncptr )(MuCtx *ctx, MuTypeNode ufuncptr, MuFuncSigNode sig);
MuTypeNode (*new_type_struct )(MuCtx *ctx, MuBundleNode b, MuTypeNode *fieldtys, int nfieldtys);
/// MUAPIPARSER fieldtys:array:nfieldtys
MuTypeNode (*new_type_hybrid )(MuCtx *ctx, MuBundleNode b, MuTypeNode *fixedtys, int nfixedtys, MuTypeNode varty);
/// MUAPIPARSER fixedtys:array:nfixedtys
MuTypeNode (*new_type_array )(MuCtx *ctx, MuBundleNode b, MuTypeNode elemty, uint64_t len);
MuTypeNode (*new_type_vector )(MuCtx *ctx, MuBundleNode b, MuTypeNode elemty, uint64_t len);
MuTypeNode (*new_type_void )(MuCtx *ctx, MuBundleNode b);
......@@ -452,12 +453,13 @@ struct MuCtx {
// Create function signatures
MuFuncSigNode (*new_funcsig )(MuCtx *ctx, MuBundleNode b, MuTypeNode *paramtys, int nparamtys, MuTypeNode *rettys, int nrettys);
/// MUAPIPARSER paramtys:array:nparamtys;rettys:array:nrettys
// Create constants
// new_const_int works for int<n>, uptr and ufuncptr.
MuConstNode (*new_const_int )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, uint64_t value);
// new_const_int_ex works for int<n> with n > 64. The number is segmented into 64-bit words, lower word first.
MuConstNode (*new_const_int_ex )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, uint64_t *values, int nvalues);
MuConstNode (*new_const_int_ex )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, uint64_t *values, int nvalues); /// MUAPIPARSER values:array:nvalues
// TODO: There is only one 'float' type and one 'double' type. Theoretically the 'ty' param is unnecessary
// It is just added to mirror the text form. Eliminate them when we are ready to change the text form.
MuConstNode (*new_const_float )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, float value);
......@@ -465,7 +467,7 @@ struct MuCtx {
// new_const_null works for all general reference types, but not uptr or ufuncptr.
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, MuTypeNode ty, MuConstNode *elems, int nelems);
MuConstNode (*new_const_seq )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty, MuConstNode *elems, int nelems); /// MUAPIPARSER elems:array:nelems
// Create global cell
MuGlobalNode (*new_global_cell )(MuCtx *ctx, MuBundleNode b, MuTypeNode ty);
......@@ -501,7 +503,7 @@ struct MuCtx {
/// Create common clauses for instructions.
// Create a destination claues and add it to instruction "inst".
void (*add_dest )(MuCtx *ctx, MuInstNode inst, MuDestKind kind, MuBBNode dest, MuVarNode *vars, int nvars);
void (*add_dest )(MuCtx *ctx, MuInstNode inst, MuDestKind kind, MuBBNode dest, MuVarNode *vars, int nvars); /// MUAPIPARSER vars:array:nvars
// Create a destination claues and add it to instruction "inst".
void (*add_keepalives)(MuCtx *ctx, MuInstNode inst, MuLocalVarNode *vars, int nvars);
......@@ -516,11 +518,11 @@ 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, MuTypeNode opnd_ty, MuVarNode opnd);
void (*add_switch_dest )(MuCtx *ctx, MuInstNode sw, MuConstNode key, MuBBNode dest, MuVarNode *vars, int nvars);
void (*add_switch_dest )(MuCtx *ctx, MuInstNode sw, MuConstNode key, MuBBNode dest, MuVarNode *vars, int nvars); /// MUAPIPARSER vars:array:nvars
MuInstNode (*new_call )(MuCtx *ctx, MuBBNode bb, MuFuncSigNode sig, MuVarNode callee, MuVarNode *args, int nargs);
MuInstNode (*new_tailcall )(MuCtx *ctx, MuBBNode bb, MuFuncSigNode sig, MuVarNode callee, MuVarNode *args, int nargs);
MuInstNode (*new_ret )(MuCtx *ctx, MuBBNode bb, MuVarNode *rvs, int nrvs);
MuInstNode (*new_call )(MuCtx *ctx, MuBBNode bb, MuFuncSigNode sig, MuVarNode callee, MuVarNode *args, int nargs); /// MUAPIPARSER args:array:nargs
MuInstNode (*new_tailcall )(MuCtx *ctx, MuBBNode bb, MuFuncSigNode sig, MuVarNode callee, MuVarNode *args, int nargs); /// MUAPIPARSER args:array:nargs
MuInstNode (*new_ret )(MuCtx *ctx, MuBBNode bb, MuVarNode *rvs, int nrvs); /// MUAPIPARSER rvs:array:nrvs
MuInstNode (*new_throw )(MuCtx *ctx, MuBBNode bb, MuVarNode exc);
MuInstNode (*new_extractvalue )(MuCtx *ctx, MuBBNode bb, MuTypeNode strty, int index, MuVarNode opnd);
......@@ -535,28 +537,28 @@ struct MuCtx {
MuInstNode (*new_allocahybrid )(MuCtx *ctx, MuBBNode bb, MuTypeNode allocty, MuTypeNode lenty, MuVarNode length);
MuInstNode (*new_getiref )(MuCtx *ctx, MuBBNode bb, MuTypeNode refty, MuVarNode opnd);
MuInstNode (*new_getfieldiref )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuTypeNode refty, int index, MuVarNode opnd);
MuInstNode (*new_getelemiref )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuTypeNode refty, MuTypeNode indty, MuVarNode opnd, MuVarNode index);
MuInstNode (*new_shiftiref )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuTypeNode refty, MuTypeNode offty, MuVarNode opnd, MuVarNode offset);
MuInstNode (*new_getvarpartiref)(MuCtx *ctx, MuBBNode bb, int is_ptr, MuTypeNode refty, MuVarNode opnd);
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, MuTypeNode refTy, MuVarNode loc, MuVarNode opnd);
MuInstNode (*new_getfieldiref )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuTypeNode refty, int index, MuVarNode opnd); /// MUAPIPARSER is_ptr:bool
MuInstNode (*new_getelemiref )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuTypeNode refty, MuTypeNode indty, MuVarNode opnd, MuVarNode index); /// MUAPIPARSER is_ptr:bool
MuInstNode (*new_shiftiref )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuTypeNode refty, MuTypeNode offty, MuVarNode opnd, MuVarNode offset); /// MUAPIPARSER is_ptr:bool
MuInstNode (*new_getvarpartiref)(MuCtx *ctx, MuBBNode bb, int is_ptr, MuTypeNode refty, MuVarNode opnd); /// MUAPIPARSER is_ptr:bool
MuInstNode (*new_load )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuMemOrd ord, MuTypeNode refty, MuVarNode loc); /// MUAPIPARSER is_ptr:bool
MuInstNode (*new_store )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuMemOrd ord, MuTypeNode refty, MuVarNode loc, MuVarNode newval); /// MUAPIPARSER is_ptr:bool
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); /// MUAPIPARSER is_ptr:bool;is_weak:bool
MuInstNode (*new_atomicrmw )(MuCtx *ctx, MuBBNode bb, int is_ptr, MuMemOrd ord, MuAtomicRMWOp optr, MuTypeNode refTy, MuVarNode loc, MuVarNode opnd); /// MUAPIPARSER is_ptr:bool
MuInstNode (*new_fence )(MuCtx *ctx, MuBBNode bb, MuMemOrd ord);
MuInstNode (*new_trap )(MuCtx *ctx, MuBBNode bb, MuTypeNode *rettys, int nrettys);
MuInstNode (*new_watchpoint )(MuCtx *ctx, MuBBNode bb, MuWPID wpid, MuTypeNode *rettys, int nrettys);
MuInstNode (*new_trap )(MuCtx *ctx, MuBBNode bb, MuTypeNode *rettys, int nrettys); /// MUAPIPARSER rettys:array:nrettys
MuInstNode (*new_watchpoint )(MuCtx *ctx, MuBBNode bb, MuWPID wpid, MuTypeNode *rettys, int nrettys); /// MUAPIPARSER rettys:array:nrettys
MuInstNode (*new_wpbranch )(MuCtx *ctx, MuBBNode bb, MuWPID wpid);
MuInstNode (*new_ccall )(MuCtx *ctx, MuBBNode bb, MuCallConv callconv, MuTypeNode callee_ty, MuFuncSigNode sig, MuVarNode callee, MuVarNode *args, int nargs);
MuInstNode (*new_ccall )(MuCtx *ctx, MuBBNode bb, MuCallConv callconv, MuTypeNode callee_ty, MuFuncSigNode sig, MuVarNode callee, MuVarNode *args, int nargs); /// MUAPIPARSER args:array:nargs
MuInstNode (*new_newthread )(MuCtx *ctx, MuBBNode bb, MuVarNode stack, MuVarNode threadlocal);
MuInstNode (*new_swapstack_ret )(MuCtx *ctx, MuBBNode bb, MuVarNode swappee, MuTypeNode *ret_tys, int nret_tys);
MuInstNode (*new_swapstack_ret )(MuCtx *ctx, MuBBNode bb, MuVarNode swappee, MuTypeNode *ret_tys, int nret_tys); /// MUAPIPARSER ret_tys:array: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); /// MUAPIPARSER tys:array:nvars;ret_tys:array:nret_tys
void (*set_newstack_throw_exc )(MuCtx *ctx, MuInstNode inst, MuVarNode exc);
MuInstNode (*new_comminst )(MuCtx *ctx, MuBBNode bb, MuCommInst opcode,
......@@ -564,6 +566,7 @@ struct MuCtx {
MuTypeNode *tys, int ntys,
MuFuncSigNode *sigs, int nsigs,
MuVarNode *args, int nargs);
/// MUAPIPARSER flags:array:nflags;tys:array:ntys;sigs:array:nsigs;args:array:nargs
};
// Common instruction opcodes
......
"""
Parse the muapi.h so that you can generate different bindings.
The result will be a simple JSON object (dict of dicts).
"""
import sys
import re
r_commpragma = re.compile(r'///\s*MUAPIPARSER:(.*)$')
r_comment = re.compile(r'//.*$', re.MULTILINE)
r_decl = re.compile(r'(?P<ret>\w+\s*\*?)\s*\(\s*\*\s*(?P<name>\w+)\s*\)\s*\((?P<params>[^)]*)\)\s*;\s*(?:///\s*MUAPIPARSER\s+(?P<pragma>.*)$)?', re.MULTILINE)
r_param = re.compile(r'\s*(?P<type>\w+\s*\*?)\s*(?P<name>\w+)')
r_value_ty = re.compile(r'Mu\w*(Value|Node)')
r_define = re.compile(r'#define\s*(?P<name>\w+)\s*(?P<value>\w+)')
r_struct_start = re.compile(r'^struct\s+(\w+)\s*\{')
r_struct_end = re.compile(r'^\};')
def filter_ret_ty(text):
return text.replace(" ","")
def extract_params(text):
params = []
for text1 in text.split(','):
ty, name = r_param.search(text1).groups()
ty = ty.replace(" ",'')
params.append({"type": ty, "name": name})
return params
def extract_pragmas(text):
text = text.strip()
if len(text) == 0:
return []
else:
return text.split(";")
def extract_methods(body):
methods = []
for ret, name, params, pragma in r_decl.findall(body):
methods.append({
"name": name,
"params": extract_params(params),
"ret_ty": filter_ret_ty(ret),
"pragmas": extract_pragmas(pragma),
})
return methods
def extract_struct(lines, name):
for i in range(len(lines)):
m = r_struct_start.search(lines[i])
if m is not None and m.group(1) == name:
for j in range(i+1, len(lines)):
m2 = r_struct_end.search(lines[j])
if m2 is not None:
body = lines[i+1:j]
return "\n".join(body)
else:
raise Exception("Cannot find the end of struct {}".format(name))
else:
raise Exception("Cannot find the start of struct {}".format(name))
def extract_enums(lines, typename, pattern):
defs = []
for line in lines:
m = r_define.search(line)
if m is not None:
name, value = m.groups()
if pattern.search(name) is not None:
defs.append({"name": name, "value": value})
return {
"name": typename,
"defs": defs,
}
_top_level_structs = ["MuVM", "MuCtx"]
_enums = [(typename, re.compile(regex)) for typename, regex in [
("MuTrapHandlerResult", r'^MU_(THREAD|REBIND)'),
("MuDestKind", r'^MU_DEST_'),
("MuBinOptr", r'^MU_BINOP_'),
("MuCmpOptr", r'^MU_CMP_'),
("MuConvOptr", r'^MU_CONV_'),
("MuMemOrd", r'^MU_ORD_'),
("MuAtomicRMWOp", r'^MU_ARMW_'),
("MuFlag", r'^MU_CC_'),
]]
def parse_muapi(text):
structs = []
lines = text.splitlines()
for sn in _top_level_structs:
b = extract_struct(lines, sn)
methods = extract_methods(b)
structs.append({"name": sn, "methods": methods})
enums = []
for tn,pat in _enums:
enums.append(extract_enums(lines, tn, pat))
return {
"structs": structs,
"enums": enums,
}
if __name__=='__main__':
import sys, pprint, shutil
width = 80
try:
width, height = shutil.get_terminal_size((80, 25))
except:
pass
text = sys.stdin.read()
pprint.pprint(parse_muapi(text), width=width)
"""
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"
target_begin = '/// SCRIPT: INSERT BEGIN'
target_begin = '/// SCRIPT: INSERT END'
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.refimpl.nat
object CDefs {
}
\ 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