Commit 73e6de36 authored by Kunshan Wang's avatar Kunshan Wang

Reimpl IRBuilder, support get_inst_res

Fixes issue #59
parent 93de3cde
......@@ -561,8 +561,9 @@ struct MuCtx {
// Create an exception parameter node and add it to the basic block "bb".
MuExcParamNode (*new_exc_param )(MuCtx *ctx, MuBBNode bb);
// Create an instruction result. It becomes the next result of "inst".
MuInstResNode (*new_inst_res )(MuCtx *ctx, MuInstNode inst);
// Get instruction result nodes from an instruction.
MuInstResNode (*get_inst_res )(MuCtx *ctx, MuInstNode inst, int index);
int (*get_num_inst_res)(MuCtx *ctx, MuInstNode inst);
/// Create common clauses for instructions.
......@@ -634,7 +635,7 @@ struct MuCtx {
};
// Common instruction opcodes
/// SCRIPT: GENERATED COMMINSTS BEGIN
/// GEN:BEGIN:COMMINSTS
#define MU_CI_UVM_NEW_STACK ((MuCommInst)0x201) /// MUAPIPARSER muname:@uvm.new_stack
#define MU_CI_UVM_KILL_STACK ((MuCommInst)0x202) /// MUAPIPARSER muname:@uvm.kill_stack
#define MU_CI_UVM_THREAD_EXIT ((MuCommInst)0x203) /// MUAPIPARSER muname:@uvm.thread_exit
......@@ -716,58 +717,60 @@ struct MuCtx {
#define MU_CI_UVM_IRBUILDER_NEW_CONST_DOUBLE ((MuCommInst)0x323) /// MUAPIPARSER muname:@uvm.irbuilder.new_const_double
#define MU_CI_UVM_IRBUILDER_NEW_CONST_NULL ((MuCommInst)0x324) /// MUAPIPARSER muname:@uvm.irbuilder.new_const_null
#define MU_CI_UVM_IRBUILDER_NEW_CONST_SEQ ((MuCommInst)0x325) /// MUAPIPARSER muname:@uvm.irbuilder.new_const_seq
#define MU_CI_UVM_IRBUILDER_NEW_GLOBAL_CELL ((MuCommInst)0x326) /// MUAPIPARSER muname:@uvm.irbuilder.new_global_cell
#define MU_CI_UVM_IRBUILDER_NEW_FUNC ((MuCommInst)0x327) /// MUAPIPARSER muname:@uvm.irbuilder.new_func
#define MU_CI_UVM_IRBUILDER_NEW_FUNC_VER ((MuCommInst)0x328) /// MUAPIPARSER muname:@uvm.irbuilder.new_func_ver
#define MU_CI_UVM_IRBUILDER_NEW_EXP_FUNC ((MuCommInst)0x329) /// MUAPIPARSER muname:@uvm.irbuilder.new_exp_func
#define MU_CI_UVM_IRBUILDER_NEW_BB ((MuCommInst)0x32a) /// MUAPIPARSER muname:@uvm.irbuilder.new_bb
#define MU_CI_UVM_IRBUILDER_NEW_NOR_PARAM ((MuCommInst)0x32b) /// MUAPIPARSER muname:@uvm.irbuilder.new_nor_param
#define MU_CI_UVM_IRBUILDER_NEW_EXC_PARAM ((MuCommInst)0x32c) /// MUAPIPARSER muname:@uvm.irbuilder.new_exc_param
#define MU_CI_UVM_IRBUILDER_NEW_INST_RES ((MuCommInst)0x32d) /// MUAPIPARSER muname:@uvm.irbuilder.new_inst_res
#define MU_CI_UVM_IRBUILDER_ADD_DEST ((MuCommInst)0x32e) /// MUAPIPARSER muname:@uvm.irbuilder.add_dest
#define MU_CI_UVM_IRBUILDER_ADD_KEEPALIVES ((MuCommInst)0x32f) /// MUAPIPARSER muname:@uvm.irbuilder.add_keepalives
#define MU_CI_UVM_IRBUILDER_NEW_BINOP ((MuCommInst)0x330) /// MUAPIPARSER muname:@uvm.irbuilder.new_binop
#define MU_CI_UVM_IRBUILDER_NEW_CMP ((MuCommInst)0x331) /// MUAPIPARSER muname:@uvm.irbuilder.new_cmp
#define MU_CI_UVM_IRBUILDER_NEW_CONV ((MuCommInst)0x332) /// MUAPIPARSER muname:@uvm.irbuilder.new_conv
#define MU_CI_UVM_IRBUILDER_NEW_SELECT ((MuCommInst)0x333) /// MUAPIPARSER muname:@uvm.irbuilder.new_select
#define MU_CI_UVM_IRBUILDER_NEW_BRANCH ((MuCommInst)0x334) /// MUAPIPARSER muname:@uvm.irbuilder.new_branch
#define MU_CI_UVM_IRBUILDER_NEW_BRANCH2 ((MuCommInst)0x335) /// MUAPIPARSER muname:@uvm.irbuilder.new_branch2
#define MU_CI_UVM_IRBUILDER_NEW_SWITCH ((MuCommInst)0x336) /// MUAPIPARSER muname:@uvm.irbuilder.new_switch
#define MU_CI_UVM_IRBUILDER_ADD_SWITCH_DEST ((MuCommInst)0x337) /// MUAPIPARSER muname:@uvm.irbuilder.add_switch_dest
#define MU_CI_UVM_IRBUILDER_NEW_CALL ((MuCommInst)0x338) /// MUAPIPARSER muname:@uvm.irbuilder.new_call
#define MU_CI_UVM_IRBUILDER_NEW_TAILCALL ((MuCommInst)0x339) /// MUAPIPARSER muname:@uvm.irbuilder.new_tailcall
#define MU_CI_UVM_IRBUILDER_NEW_RET ((MuCommInst)0x33a) /// MUAPIPARSER muname:@uvm.irbuilder.new_ret
#define MU_CI_UVM_IRBUILDER_NEW_THROW ((MuCommInst)0x33b) /// MUAPIPARSER muname:@uvm.irbuilder.new_throw
#define MU_CI_UVM_IRBUILDER_NEW_EXTRACTVALUE ((MuCommInst)0x33c) /// MUAPIPARSER muname:@uvm.irbuilder.new_extractvalue
#define MU_CI_UVM_IRBUILDER_NEW_INSERTVALUE ((MuCommInst)0x33d) /// MUAPIPARSER muname:@uvm.irbuilder.new_insertvalue
#define MU_CI_UVM_IRBUILDER_NEW_EXTRACTELEMENT ((MuCommInst)0x33e) /// MUAPIPARSER muname:@uvm.irbuilder.new_extractelement
#define MU_CI_UVM_IRBUILDER_NEW_INSERTELEMENT ((MuCommInst)0x33f) /// MUAPIPARSER muname:@uvm.irbuilder.new_insertelement
#define MU_CI_UVM_IRBUILDER_NEW_SHUFFLEVECTOR ((MuCommInst)0x340) /// MUAPIPARSER muname:@uvm.irbuilder.new_shufflevector
#define MU_CI_UVM_IRBUILDER_NEW_NEW ((MuCommInst)0x341) /// MUAPIPARSER muname:@uvm.irbuilder.new_new
#define MU_CI_UVM_IRBUILDER_NEW_NEWHYBRID ((MuCommInst)0x342) /// MUAPIPARSER muname:@uvm.irbuilder.new_newhybrid
#define MU_CI_UVM_IRBUILDER_NEW_ALLOCA ((MuCommInst)0x343) /// MUAPIPARSER muname:@uvm.irbuilder.new_alloca
#define MU_CI_UVM_IRBUILDER_NEW_ALLOCAHYBRID ((MuCommInst)0x344) /// MUAPIPARSER muname:@uvm.irbuilder.new_allocahybrid
#define MU_CI_UVM_IRBUILDER_NEW_GETIREF ((MuCommInst)0x345) /// MUAPIPARSER muname:@uvm.irbuilder.new_getiref
#define MU_CI_UVM_IRBUILDER_NEW_GETFIELDIREF ((MuCommInst)0x346) /// MUAPIPARSER muname:@uvm.irbuilder.new_getfieldiref
#define MU_CI_UVM_IRBUILDER_NEW_GETELEMIREF ((MuCommInst)0x347) /// MUAPIPARSER muname:@uvm.irbuilder.new_getelemiref
#define MU_CI_UVM_IRBUILDER_NEW_SHIFTIREF ((MuCommInst)0x348) /// MUAPIPARSER muname:@uvm.irbuilder.new_shiftiref
#define MU_CI_UVM_IRBUILDER_NEW_GETVARPARTIREF ((MuCommInst)0x349) /// MUAPIPARSER muname:@uvm.irbuilder.new_getvarpartiref
#define MU_CI_UVM_IRBUILDER_NEW_LOAD ((MuCommInst)0x34a) /// MUAPIPARSER muname:@uvm.irbuilder.new_load
#define MU_CI_UVM_IRBUILDER_NEW_STORE ((MuCommInst)0x34b) /// MUAPIPARSER muname:@uvm.irbuilder.new_store
#define MU_CI_UVM_IRBUILDER_NEW_CMPXCHG ((MuCommInst)0x34c) /// MUAPIPARSER muname:@uvm.irbuilder.new_cmpxchg
#define MU_CI_UVM_IRBUILDER_NEW_ATOMICRMW ((MuCommInst)0x34d) /// MUAPIPARSER muname:@uvm.irbuilder.new_atomicrmw
#define MU_CI_UVM_IRBUILDER_NEW_FENCE ((MuCommInst)0x34e) /// MUAPIPARSER muname:@uvm.irbuilder.new_fence
#define MU_CI_UVM_IRBUILDER_NEW_TRAP ((MuCommInst)0x34f) /// MUAPIPARSER muname:@uvm.irbuilder.new_trap
#define MU_CI_UVM_IRBUILDER_NEW_WATCHPOINT ((MuCommInst)0x350) /// MUAPIPARSER muname:@uvm.irbuilder.new_watchpoint
#define MU_CI_UVM_IRBUILDER_NEW_WPBRANCH ((MuCommInst)0x351) /// MUAPIPARSER muname:@uvm.irbuilder.new_wpbranch
#define MU_CI_UVM_IRBUILDER_NEW_CCALL ((MuCommInst)0x352) /// MUAPIPARSER muname:@uvm.irbuilder.new_ccall
#define MU_CI_UVM_IRBUILDER_NEW_NEWTHREAD ((MuCommInst)0x353) /// MUAPIPARSER muname:@uvm.irbuilder.new_newthread
#define MU_CI_UVM_IRBUILDER_NEW_SWAPSTACK_RET ((MuCommInst)0x354) /// MUAPIPARSER muname:@uvm.irbuilder.new_swapstack_ret
#define MU_CI_UVM_IRBUILDER_NEW_SWAPSTACK_KILL ((MuCommInst)0x355) /// MUAPIPARSER muname:@uvm.irbuilder.new_swapstack_kill
#define MU_CI_UVM_IRBUILDER_SET_NEWSTACK_PASS_VALUES ((MuCommInst)0x356) /// MUAPIPARSER muname:@uvm.irbuilder.set_newstack_pass_values
#define MU_CI_UVM_IRBUILDER_SET_NEWSTACK_THROW_EXC ((MuCommInst)0x357) /// MUAPIPARSER muname:@uvm.irbuilder.set_newstack_throw_exc
#define MU_CI_UVM_IRBUILDER_NEW_COMMINST ((MuCommInst)0x358) /// MUAPIPARSER muname:@uvm.irbuilder.new_comminst
/// SCRIPT: GENERATED COMMINSTS END
#define MU_CI_UVM_IRBUILDER_NEW_CONST_EXTERN ((MuCommInst)0x326) /// MUAPIPARSER muname:@uvm.irbuilder.new_const_extern
#define MU_CI_UVM_IRBUILDER_NEW_GLOBAL_CELL ((MuCommInst)0x327) /// MUAPIPARSER muname:@uvm.irbuilder.new_global_cell
#define MU_CI_UVM_IRBUILDER_NEW_FUNC ((MuCommInst)0x328) /// MUAPIPARSER muname:@uvm.irbuilder.new_func
#define MU_CI_UVM_IRBUILDER_NEW_FUNC_VER ((MuCommInst)0x329) /// MUAPIPARSER muname:@uvm.irbuilder.new_func_ver
#define MU_CI_UVM_IRBUILDER_NEW_EXP_FUNC ((MuCommInst)0x32a) /// MUAPIPARSER muname:@uvm.irbuilder.new_exp_func
#define MU_CI_UVM_IRBUILDER_NEW_BB ((MuCommInst)0x32b) /// MUAPIPARSER muname:@uvm.irbuilder.new_bb
#define MU_CI_UVM_IRBUILDER_NEW_NOR_PARAM ((MuCommInst)0x32c) /// MUAPIPARSER muname:@uvm.irbuilder.new_nor_param
#define MU_CI_UVM_IRBUILDER_NEW_EXC_PARAM ((MuCommInst)0x32d) /// MUAPIPARSER muname:@uvm.irbuilder.new_exc_param
#define MU_CI_UVM_IRBUILDER_GET_INST_RES ((MuCommInst)0x32e) /// MUAPIPARSER muname:@uvm.irbuilder.get_inst_res
#define MU_CI_UVM_IRBUILDER_GET_NUM_INST_RES ((MuCommInst)0x32f) /// MUAPIPARSER muname:@uvm.irbuilder.get_num_inst_res
#define MU_CI_UVM_IRBUILDER_ADD_DEST ((MuCommInst)0x330) /// MUAPIPARSER muname:@uvm.irbuilder.add_dest
#define MU_CI_UVM_IRBUILDER_ADD_KEEPALIVES ((MuCommInst)0x331) /// MUAPIPARSER muname:@uvm.irbuilder.add_keepalives
#define MU_CI_UVM_IRBUILDER_NEW_BINOP ((MuCommInst)0x332) /// MUAPIPARSER muname:@uvm.irbuilder.new_binop
#define MU_CI_UVM_IRBUILDER_NEW_CMP ((MuCommInst)0x333) /// MUAPIPARSER muname:@uvm.irbuilder.new_cmp
#define MU_CI_UVM_IRBUILDER_NEW_CONV ((MuCommInst)0x334) /// MUAPIPARSER muname:@uvm.irbuilder.new_conv
#define MU_CI_UVM_IRBUILDER_NEW_SELECT ((MuCommInst)0x335) /// MUAPIPARSER muname:@uvm.irbuilder.new_select
#define MU_CI_UVM_IRBUILDER_NEW_BRANCH ((MuCommInst)0x336) /// MUAPIPARSER muname:@uvm.irbuilder.new_branch
#define MU_CI_UVM_IRBUILDER_NEW_BRANCH2 ((MuCommInst)0x337) /// MUAPIPARSER muname:@uvm.irbuilder.new_branch2
#define MU_CI_UVM_IRBUILDER_NEW_SWITCH ((MuCommInst)0x338) /// MUAPIPARSER muname:@uvm.irbuilder.new_switch
#define MU_CI_UVM_IRBUILDER_ADD_SWITCH_DEST ((MuCommInst)0x339) /// MUAPIPARSER muname:@uvm.irbuilder.add_switch_dest
#define MU_CI_UVM_IRBUILDER_NEW_CALL ((MuCommInst)0x33a) /// MUAPIPARSER muname:@uvm.irbuilder.new_call
#define MU_CI_UVM_IRBUILDER_NEW_TAILCALL ((MuCommInst)0x33b) /// MUAPIPARSER muname:@uvm.irbuilder.new_tailcall
#define MU_CI_UVM_IRBUILDER_NEW_RET ((MuCommInst)0x33c) /// MUAPIPARSER muname:@uvm.irbuilder.new_ret
#define MU_CI_UVM_IRBUILDER_NEW_THROW ((MuCommInst)0x33d) /// MUAPIPARSER muname:@uvm.irbuilder.new_throw
#define MU_CI_UVM_IRBUILDER_NEW_EXTRACTVALUE ((MuCommInst)0x33e) /// MUAPIPARSER muname:@uvm.irbuilder.new_extractvalue
#define MU_CI_UVM_IRBUILDER_NEW_INSERTVALUE ((MuCommInst)0x33f) /// MUAPIPARSER muname:@uvm.irbuilder.new_insertvalue
#define MU_CI_UVM_IRBUILDER_NEW_EXTRACTELEMENT ((MuCommInst)0x340) /// MUAPIPARSER muname:@uvm.irbuilder.new_extractelement
#define MU_CI_UVM_IRBUILDER_NEW_INSERTELEMENT ((MuCommInst)0x341) /// MUAPIPARSER muname:@uvm.irbuilder.new_insertelement
#define MU_CI_UVM_IRBUILDER_NEW_SHUFFLEVECTOR ((MuCommInst)0x342) /// MUAPIPARSER muname:@uvm.irbuilder.new_shufflevector
#define MU_CI_UVM_IRBUILDER_NEW_NEW ((MuCommInst)0x343) /// MUAPIPARSER muname:@uvm.irbuilder.new_new
#define MU_CI_UVM_IRBUILDER_NEW_NEWHYBRID ((MuCommInst)0x344) /// MUAPIPARSER muname:@uvm.irbuilder.new_newhybrid
#define MU_CI_UVM_IRBUILDER_NEW_ALLOCA ((MuCommInst)0x345) /// MUAPIPARSER muname:@uvm.irbuilder.new_alloca
#define MU_CI_UVM_IRBUILDER_NEW_ALLOCAHYBRID ((MuCommInst)0x346) /// MUAPIPARSER muname:@uvm.irbuilder.new_allocahybrid
#define MU_CI_UVM_IRBUILDER_NEW_GETIREF ((MuCommInst)0x347) /// MUAPIPARSER muname:@uvm.irbuilder.new_getiref
#define MU_CI_UVM_IRBUILDER_NEW_GETFIELDIREF ((MuCommInst)0x348) /// MUAPIPARSER muname:@uvm.irbuilder.new_getfieldiref
#define MU_CI_UVM_IRBUILDER_NEW_GETELEMIREF ((MuCommInst)0x349) /// MUAPIPARSER muname:@uvm.irbuilder.new_getelemiref
#define MU_CI_UVM_IRBUILDER_NEW_SHIFTIREF ((MuCommInst)0x34a) /// MUAPIPARSER muname:@uvm.irbuilder.new_shiftiref
#define MU_CI_UVM_IRBUILDER_NEW_GETVARPARTIREF ((MuCommInst)0x34b) /// MUAPIPARSER muname:@uvm.irbuilder.new_getvarpartiref
#define MU_CI_UVM_IRBUILDER_NEW_LOAD ((MuCommInst)0x34c) /// MUAPIPARSER muname:@uvm.irbuilder.new_load
#define MU_CI_UVM_IRBUILDER_NEW_STORE ((MuCommInst)0x34d) /// MUAPIPARSER muname:@uvm.irbuilder.new_store
#define MU_CI_UVM_IRBUILDER_NEW_CMPXCHG ((MuCommInst)0x34e) /// MUAPIPARSER muname:@uvm.irbuilder.new_cmpxchg
#define MU_CI_UVM_IRBUILDER_NEW_ATOMICRMW ((MuCommInst)0x34f) /// MUAPIPARSER muname:@uvm.irbuilder.new_atomicrmw
#define MU_CI_UVM_IRBUILDER_NEW_FENCE ((MuCommInst)0x350) /// MUAPIPARSER muname:@uvm.irbuilder.new_fence
#define MU_CI_UVM_IRBUILDER_NEW_TRAP ((MuCommInst)0x351) /// MUAPIPARSER muname:@uvm.irbuilder.new_trap
#define MU_CI_UVM_IRBUILDER_NEW_WATCHPOINT ((MuCommInst)0x352) /// MUAPIPARSER muname:@uvm.irbuilder.new_watchpoint
#define MU_CI_UVM_IRBUILDER_NEW_WPBRANCH ((MuCommInst)0x353) /// MUAPIPARSER muname:@uvm.irbuilder.new_wpbranch
#define MU_CI_UVM_IRBUILDER_NEW_CCALL ((MuCommInst)0x354) /// MUAPIPARSER muname:@uvm.irbuilder.new_ccall
#define MU_CI_UVM_IRBUILDER_NEW_NEWTHREAD ((MuCommInst)0x355) /// MUAPIPARSER muname:@uvm.irbuilder.new_newthread
#define MU_CI_UVM_IRBUILDER_NEW_SWAPSTACK_RET ((MuCommInst)0x356) /// MUAPIPARSER muname:@uvm.irbuilder.new_swapstack_ret
#define MU_CI_UVM_IRBUILDER_NEW_SWAPSTACK_KILL ((MuCommInst)0x357) /// MUAPIPARSER muname:@uvm.irbuilder.new_swapstack_kill
#define MU_CI_UVM_IRBUILDER_SET_NEWSTACK_PASS_VALUES ((MuCommInst)0x358) /// MUAPIPARSER muname:@uvm.irbuilder.set_newstack_pass_values
#define MU_CI_UVM_IRBUILDER_SET_NEWSTACK_THROW_EXC ((MuCommInst)0x359) /// MUAPIPARSER muname:@uvm.irbuilder.set_newstack_throw_exc
#define MU_CI_UVM_IRBUILDER_NEW_COMMINST ((MuCommInst)0x35a) /// MUAPIPARSER muname:@uvm.irbuilder.new_comminst
/// GEN:END:COMMINSTS
#ifdef __cplusplus
}
......
......@@ -14,61 +14,99 @@ begin = "SCRIPT: BEGIN HERE"
end = "SCRIPT: END HERE"
replaces = [(re.compile(x), y) for (x,y) in [
(r'BN', 'MuBundleNode'),
(r'(CN|ChildNode)\[(_\s*<:\s*)?Identified\]', 'MuChildNode'),
(r'(CN|ChildNode)\[(_\s*<:\s*)?IdentifiedSettable\]', 'MuChildNode'),
(r'(CN|ChildNode)\[Type\w*\]', 'MuTypeNode'),
(r'(CN|ChildNode)\[Abstract\w+Type\]', 'MuTypeNode'),
(r'(CN|ChildNode)\[FuncSig\]', 'MuFuncSigNode'),
(r'(CN|ChildNode)\[Const\w+\]', 'MuConstNode'),
(r'(CN|ChildNode)\[GlobalCell\]', 'MuGlobalNode'),
(r'(CN|ChildNode)\[Function\]', 'MuFuncNode'),
(r'(CN|ChildNode)\[ExposedFunc\]', 'MuExpFuncNode'),
(r'(CN|ChildNode)\[FuncVer\]', 'MuFuncVerNode'),
(r'(CN|ChildNode)\[BasicBlock\]', 'MuBBNode'),
(r'(CN|ChildNode)\[BB\]', 'MuBBNode'),
(r'(CN|ChildNode)\[SSAVariable\]', 'MuVarNode'),
(r'(CN|ChildNode)\[Var\]', 'MuVarNode'),
(r'(CN|ChildNode)\[LocalVariable\]', 'MuLocalVarNode'),
(r'(CN|ChildNode)\[NorParam\]', 'MuNorParamNode'),
(r'(CN|ChildNode)\[ExcParam\]', 'MuExcParamNode'),
(r'(CN|ChildNode)\[InstResult\]', 'MuInstResNode'),
(r'(CN|ChildNode)\[Inst\w+\]', 'MuInstNode'),
(r'(CN|ChildNode)\[HasKeepaliveClause\]', 'MuInstNode'),
(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'),
]]
sig = re.compile(r'^( def\s+(\w+)\s*\(([^)]*)\):\s+\w+\s+=)', re.MULTILINE)
arg = re.compile(r'(\w*):\s+([a-zA-Z0-9\[\]]+)')
sig = re.compile(r'^( def\s+(\w+)\s*\(([^)]*)\):\s+(\w+)\s+=)', re.MULTILINE)
arg = re.compile(r'(\w*):\s*([a-zA-Z0-9\[\].]+)')
node_like = re.compile(r'Mu\w+Node')
node_seq_like = re.compile(r'Seq\[Mu\w+Node\]')
node_seq_like = re.compile(r'Seq\[(Mu\w+Node)\]')
_my_dir = os.path.dirname(__file__)
_refimpl2_root = os.path.join(_my_dir, "..")
irbuilder_path = os.path.join(_refimpl2_root, "src/main/scala/uvm/ir/irbuilder/IRBuilder.scala")
## No longer replace names, but just use MuIRNode[...]
#def rewrite_type(ty):
# for p, t in replaces:
# oldty = ty
# ty = p.sub(t, ty)
# if oldty != ty:
# break
# return ty
container_ty_r = re.compile(r'(Seq|Option)\[(.+)\]')
def rewrite_type(ty):
m = container_ty_r.match(ty)
if m is not None:
t1, t2 = m.groups()
return "{}[{}]".format(t1, rewrite_type(t2))
for p, t in replaces:
if p.match(ty) is not None:
return "MuIRNode[{}]".format(ty)
return ty
def main():
with open(irbuilder_path) as f:
lines = f.read()
text = injecttools.extract_lines(lines, begin, end)
for p, t in replaces:
text = p.sub(t, text)
#for p, t in replaces:
#text = p.sub(t, text)
output = io.StringIO()
for whole, name, arglist in sig.findall(text):
print(whole, "{", file=output)
for whole, name, arglist, retty in sig.findall(text):
argnames = []
argtypes_muctx = []
sanitisers = []
retty = rewrite_type(retty)
for an,at in arg.findall(arglist):
rwt = rewrite_type(at)
print(an, at, rwt)
argnames.append(an)
#print(an, at)
if node_seq_like.match(at) is not None:
print(' for((n,i) <- {}.zipWithIndex) require(!n.isNull, "{}[%d] must not be NULL".format(i))'.format(an, an), file=output)
elif node_like.match(at) is not None:
print(' require(!{}.isNull, "{} must not be NULL")'.format(an, an), file=output)
if name.startswith("new"):
print(' addHandle(irBuilder.{}({}))'.format(name, ", ".join(argnames)), file=output)
argtypes_muctx.append(rwt)
m = node_seq_like.match(rwt)
if m is not None:
sanitisers.append(' for((n,i) <- {}.zipWithIndex) require(!n.isNull, "{}[%d] must not be NULL".format(i))'.format(an, an))
elif node_like.match(rwt) is not None:
sanitisers.append(' require(!{}.isNull, "{} must not be NULL")'.format(an, an))
new_arglist = ", ".join("{}: {}".format(n,t) for n,t in zip(argnames, argtypes_muctx))
print(" def {}({}): {} = {{".format(name, new_arglist, retty), file=output)
for s in sanitisers:
print(s, file=output)
if name.startswith("new") or name in["getNode", "getInstRes"]:
print(' nodeToHandle(irBuilder.{}({}))'.format(name, ", ".join(argnames)), file=output)
else:
print(' irBuilder.{}({})'.format(name, ", ".join(argnames)), file=output)
print(" }", file=output)
......@@ -78,6 +116,10 @@ def main():
#args = arg_name.findall(a)
#print(" addHandle(irBuilder.{}({}))".format(n, ", ".join(args)))
#print(output.getvalue())
#return
injectable_files["MuCtxIRBuilderPart.scala"].inject_many({
"METHODS": output.getvalue(),
})
......
......@@ -164,13 +164,17 @@ def mu_ty_to_internal(mty):
raise Exception("I don't know how to convert to internal: {}".format(mty))
def gen_comminsts_retvals(comminsts):
lines = []
lines_retvals = []
lines_nretvals = []
for comminst in comminsts:
lines.append(' case "{}" => Seq({})'.format(
lines_retvals.append(' case "{}" => Seq({})'.format(
comminst.muname, mu_ty_to_internal(comminst.muretty)))
lines_nretvals.append(' case "{}" => {}'.format(
comminst.muname, 0 if comminst.muretty == "" else 1))
return "\n".join(lines)
return ("\n".join(lines_retvals), "\n".join(lines_nretvals))
_get_arg_meths = {
"int<64>": "asInt64.toLong",
......@@ -189,12 +193,12 @@ def get_arg_meth(mty, cty, cname):
def get_arg(ind, mty, cty, cname, is_optional):
if cty == "MuBundleNode":
meth = 'asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %{} must not be null")).asInstanceOf[BundleNode]'.format(cname)
meth = 'asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %{} must not be null")).asInstanceOf[TB]'.format(cname)
elif mty == "irnoderef":
if is_optional:
meth = 'asIRNode'
meth = 'asIRNodeWeak'
else:
meth = 'asIRNode.getOrElse(throw new UvmNullGenRefException("CommInst arg %{} must not be null"))'.format(cname)
meth = 'asIRNodeWeak.getOrElse(throw new UvmNullGenRefException("CommInst arg %{} must not be null"))'.format(cname)
else:
meth = get_arg_meth(mty, cty, cname)
return " val {} = argList({}).{}".format(cname, ind, meth)
......@@ -213,7 +217,7 @@ def set_arg_meth(mty, cty):
def set_ret(ind, mty, cty, value):
if mty == "irnoderef":
meth = 'asIRNode'
meth = 'asIRNodeWeak'
return " results({}).{} = Some({})".format(ind, meth, value)
else:
meth = set_arg_meth(mty, cty)
......@@ -359,7 +363,7 @@ def main():
comminsts = get_comminsts(ast)
comminsts_defs = gen_comminsts_defs(comminsts)
comminsts_retvals = gen_comminsts_retvals(comminsts)
comminsts_retvals, comminsts_nretvals = gen_comminsts_retvals(comminsts)
comminsts_impls = gen_comminsts_impls(comminsts)
#print(comminsts_defs)
......@@ -371,6 +375,9 @@ def main():
"internals.scala": {
"IRBUILDER_RETVALS": comminsts_retvals,
},
"InstructionResultInferer.scala": {
"IRBUILDER_RETVAL_NUMS": comminsts_nretvals,
},
"ir-ci-exec": {
"IRBUILDER_IMPL": comminsts_impls,
},
......
......@@ -19,6 +19,8 @@ injectable_files = injecttools.make_injectable_file_set(_refimpl2_root, [
["IRBUILDER_COMMINSTS"]),
("internals.scala", "src/main/scala/uvm/refimpl/internals.scala",
["IRBUILDER_RETVALS"]),
("InstructionResultInferer.scala", "src/main/scala/uvm/staticanalysis/InstructionResultInferer.scala",
["IRBUILDER_RETVAL_NUMS"]),
("ir-ci-exec", "src/main/scala/uvm/refimpl/itpr/IRBuilderCommInstExecutor.scala",
["IRBUILDER_IMPL"]),
("MuCtxIRBuilderPart.scala", "src/main/scala/uvm/refimpl/MuCtxIRBuilderPart.scala",
......
python3 irbuildertomuctx.py
python3 muapitocstubs.py
python3 muapitoirbuildercomminstsimpl.py
python3 muapitolibmupy.py
......@@ -433,57 +433,59 @@ common_instruction_opcodes = {
'@uvm.irbuilder.new_const_double': 0x323,
'@uvm.irbuilder.new_const_null': 0x324,
'@uvm.irbuilder.new_const_seq': 0x325,
'@uvm.irbuilder.new_global_cell': 0x326,
'@uvm.irbuilder.new_func': 0x327,
'@uvm.irbuilder.new_func_ver': 0x328,
'@uvm.irbuilder.new_exp_func': 0x329,
'@uvm.irbuilder.new_bb': 0x32a,
'@uvm.irbuilder.new_nor_param': 0x32b,
'@uvm.irbuilder.new_exc_param': 0x32c,
'@uvm.irbuilder.new_inst_res': 0x32d,
'@uvm.irbuilder.add_dest': 0x32e,
'@uvm.irbuilder.add_keepalives': 0x32f,
'@uvm.irbuilder.new_binop': 0x330,
'@uvm.irbuilder.new_cmp': 0x331,
'@uvm.irbuilder.new_conv': 0x332,
'@uvm.irbuilder.new_select': 0x333,
'@uvm.irbuilder.new_branch': 0x334,
'@uvm.irbuilder.new_branch2': 0x335,
'@uvm.irbuilder.new_switch': 0x336,
'@uvm.irbuilder.add_switch_dest': 0x337,
'@uvm.irbuilder.new_call': 0x338,
'@uvm.irbuilder.new_tailcall': 0x339,
'@uvm.irbuilder.new_ret': 0x33a,
'@uvm.irbuilder.new_throw': 0x33b,
'@uvm.irbuilder.new_extractvalue': 0x33c,
'@uvm.irbuilder.new_insertvalue': 0x33d,
'@uvm.irbuilder.new_extractelement': 0x33e,
'@uvm.irbuilder.new_insertelement': 0x33f,
'@uvm.irbuilder.new_shufflevector': 0x340,
'@uvm.irbuilder.new_new': 0x341,
'@uvm.irbuilder.new_newhybrid': 0x342,
'@uvm.irbuilder.new_alloca': 0x343,
'@uvm.irbuilder.new_allocahybrid': 0x344,
'@uvm.irbuilder.new_getiref': 0x345,
'@uvm.irbuilder.new_getfieldiref': 0x346,
'@uvm.irbuilder.new_getelemiref': 0x347,
'@uvm.irbuilder.new_shiftiref': 0x348,
'@uvm.irbuilder.new_getvarpartiref': 0x349,
'@uvm.irbuilder.new_load': 0x34a,
'@uvm.irbuilder.new_store': 0x34b,
'@uvm.irbuilder.new_cmpxchg': 0x34c,
'@uvm.irbuilder.new_atomicrmw': 0x34d,
'@uvm.irbuilder.new_fence': 0x34e,
'@uvm.irbuilder.new_trap': 0x34f,
'@uvm.irbuilder.new_watchpoint': 0x350,
'@uvm.irbuilder.new_wpbranch': 0x351,
'@uvm.irbuilder.new_ccall': 0x352,
'@uvm.irbuilder.new_newthread': 0x353,
'@uvm.irbuilder.new_swapstack_ret': 0x354,
'@uvm.irbuilder.new_swapstack_kill': 0x355,
'@uvm.irbuilder.set_newstack_pass_values': 0x356,
'@uvm.irbuilder.set_newstack_throw_exc': 0x357,
'@uvm.irbuilder.new_comminst': 0x358,
'@uvm.irbuilder.new_const_extern': 0x326,
'@uvm.irbuilder.new_global_cell': 0x327,
'@uvm.irbuilder.new_func': 0x328,
'@uvm.irbuilder.new_func_ver': 0x329,
'@uvm.irbuilder.new_exp_func': 0x32a,
'@uvm.irbuilder.new_bb': 0x32b,
'@uvm.irbuilder.new_nor_param': 0x32c,
'@uvm.irbuilder.new_exc_param': 0x32d,
'@uvm.irbuilder.get_inst_res': 0x32e,
'@uvm.irbuilder.get_num_inst_res': 0x32f,
'@uvm.irbuilder.add_dest': 0x330,
'@uvm.irbuilder.add_keepalives': 0x331,
'@uvm.irbuilder.new_binop': 0x332,
'@uvm.irbuilder.new_cmp': 0x333,
'@uvm.irbuilder.new_conv': 0x334,
'@uvm.irbuilder.new_select': 0x335,
'@uvm.irbuilder.new_branch': 0x336,
'@uvm.irbuilder.new_branch2': 0x337,
'@uvm.irbuilder.new_switch': 0x338,
'@uvm.irbuilder.add_switch_dest': 0x339,
'@uvm.irbuilder.new_call': 0x33a,
'@uvm.irbuilder.new_tailcall': 0x33b,
'@uvm.irbuilder.new_ret': 0x33c,
'@uvm.irbuilder.new_throw': 0x33d,
'@uvm.irbuilder.new_extractvalue': 0x33e,
'@uvm.irbuilder.new_insertvalue': 0x33f,
'@uvm.irbuilder.new_extractelement': 0x340,
'@uvm.irbuilder.new_insertelement': 0x341,
'@uvm.irbuilder.new_shufflevector': 0x342,
'@uvm.irbuilder.new_new': 0x343,
'@uvm.irbuilder.new_newhybrid': 0x344,
'@uvm.irbuilder.new_alloca': 0x345,
'@uvm.irbuilder.new_allocahybrid': 0x346,
'@uvm.irbuilder.new_getiref': 0x347,
'@uvm.irbuilder.new_getfieldiref': 0x348,
'@uvm.irbuilder.new_getelemiref': 0x349,
'@uvm.irbuilder.new_shiftiref': 0x34a,
'@uvm.irbuilder.new_getvarpartiref': 0x34b,
'@uvm.irbuilder.new_load': 0x34c,
'@uvm.irbuilder.new_store': 0x34d,
'@uvm.irbuilder.new_cmpxchg': 0x34e,
'@uvm.irbuilder.new_atomicrmw': 0x34f,
'@uvm.irbuilder.new_fence': 0x350,
'@uvm.irbuilder.new_trap': 0x351,
'@uvm.irbuilder.new_watchpoint': 0x352,
'@uvm.irbuilder.new_wpbranch': 0x353,
'@uvm.irbuilder.new_ccall': 0x354,
'@uvm.irbuilder.new_newthread': 0x355,
'@uvm.irbuilder.new_swapstack_ret': 0x356,
'@uvm.irbuilder.new_swapstack_kill': 0x357,
'@uvm.irbuilder.set_newstack_pass_values': 0x358,
'@uvm.irbuilder.set_newstack_throw_exc': 0x359,
'@uvm.irbuilder.new_comminst': 0x35a,
}
## GEN:END:CENUMS
......@@ -1370,7 +1372,8 @@ _initialize_methods(MuCtx, [
('new_bb', MuBBNode, [MuFuncVerNode]),
('new_nor_param', MuNorParamNode, [MuBBNode, MuTypeNode]),
('new_exc_param', MuExcParamNode, [MuBBNode]),
('new_inst_res', MuInstResNode, [MuInstNode]),
('get_inst_res', MuInstResNode, [MuInstNode, ctypes.c_int]),
('get_num_inst_res', ctypes.c_int, [MuInstNode]),
('add_dest', None, [MuInstNode, CMuDestKind, MuBBNode, ctypes.c_void_p, CMuArraySize]),
('add_keepalives', None, [MuInstNode, ctypes.c_void_p, CMuArraySize]),
('new_binop', MuInstNode, [MuBBNode, CMuBinOptr, MuTypeNode, MuVarNode, MuVarNode]),
......
......@@ -5,25 +5,36 @@ import uvm.ssavariables._
import scala.collection.mutable.HashMap
import scala.collection.mutable.ArrayBuffer
/**
* The top-level type for all Mu IR AST nodes. Convenient for the IRBuilder API.
*/
trait IRNode
/**
* All nodes that are not Bundle.
*/
trait ChildNode extends IRNode with IdentifiedSettable
/**
* Abstract type for all top-level definitions. Unlike the text form, FuncVer is not considered as top-level, but a sub-
* node of Function.
*/
trait TopLevel extends Identified
trait TopLevel extends ChildNode
abstract class Bundle {
abstract class Bundle extends IRNode {
/*
* There is a hierarchy of namespaces. A subnode is a subset of the parent.
*
* + allNs // All globally Identified entities
* + typeNs // All types
* + funcSigNs // All function signatures
* + topLevelNs // All globally Identified entities
* + typeNs // All types
* + funcSigNs // All function signatures
* + globalVarNs // Global variables
* + constantNs // Constants
* + globalCellNs // Global cells
* + funcNs // Functions
* + expFuncNs // Exposed functions
* + funcVerNs // All function versions
* + globalVarNs // Global variables
* + constantNs // Constants
* + globalCellNs // Global cells
* + funcNs // Functions
* + expFuncNs // Exposed functions
* + bbNs // Basic blocks (per function version)
* + instNs // All instructions
* + localInstNs // Instructions in a basic block (per basic block)
......@@ -33,28 +44,26 @@ abstract class Bundle {
val allNs = new NestedNamespace[Identified](None, "Mu entity")
val typeNs = allNs.makeSubSpace[Type]("type")
val funcSigNs = allNs.makeSubSpace[FuncSig]("function signature")
val funcVerNs = allNs.makeSubSpace[FuncVer]("function version")
val topLevelNs = allNs.makeSubSpace[TopLevel]("top-level definition")
val typeNs = topLevelNs.makeSubSpace[Type]("type")
val funcSigNs = topLevelNs.makeSubSpace[FuncSig]("function signature")
val globalVarNs = allNs.makeSubSpace[GlobalVariable]("global variable")
val globalVarNs = topLevelNs.makeSubSpace[GlobalVariable]("global variable")
val constantNs = globalVarNs.makeSubSpace[Constant]("constant")
val globalCellNs = globalVarNs.makeSubSpace[GlobalCell]("global cell")
val funcNs = globalVarNs.makeSubSpace[Function]("function")
val expFuncNs = globalVarNs.makeSubSpace[ExposedFunc]("exposed function")
val funcVerNs = allNs.makeSubSpace[FuncVer]("function version")
val instNs = allNs.makeSubSpace[Instruction]("instruction")
val sourceInfoRepo = new SourceInfoRepo()
def allTopLevels(): Seq[TopLevel] = {
val buf = new ArrayBuffer[TopLevel]()
buf ++= typeNs.all
buf ++= funcSigNs.all
buf ++= constantNs.all
buf ++= globalCellNs.all
buf ++= funcNs.all
buf ++= expFuncNs.all
buf ++= topLevelNs.all
buf
}
}
......@@ -147,11 +156,11 @@ class GlobalBundle extends Bundle {
// Only merge leaves
simpleMerge(typeNs, newBundle.typeNs, newBundle.sourceInfoRepo)
simpleMerge(funcSigNs, newBundle.funcSigNs, newBundle.sourceInfoRepo)
simpleMerge(funcVerNs, newBundle.funcVerNs, newBundle.sourceInfoRepo)
simpleMerge(constantNs, newBundle.constantNs, newBundle.sourceInfoRepo)
simpleMerge(globalCellNs, newBundle.globalCellNs, newBundle.sourceInfoRepo)
simpleMerge(funcNs, newBundle.funcNs, newBundle.sourceInfoRepo)
simpleMerge(expFuncNs, newBundle.expFuncNs, newBundle.sourceInfoRepo)
simpleMerge(funcVerNs, newBundle.funcVerNs, newBundle.sourceInfoRepo)
simpleMerge(instNs, newBundle.instNs, newBundle.sourceInfoRepo)
declareFunctions(newBundle.funcNs)
......
......@@ -113,49 +113,50 @@ object CommInsts extends SimpleNamespace[CommInst] {
commInst(0x32b, "@uvm.irbuilder.new_bb")
commInst(0x32c, "@uvm.irbuilder.new_nor_param")
commInst(0x32d, "@uvm.irbuilder.new_exc_param")
commInst(0x32e, "@uvm.irbuilder.new_inst_res")
commInst(0x32f, "@uvm.irbuilder.add_dest")
commInst(0x330, "@uvm.irbuilder.add_keepalives")
commInst(0x331, "@uvm.irbuilder.new_binop")
commInst(0x332, "@uvm.irbuilder.new_cmp")
commInst(0x333, "@uvm.irbuilder.new_conv")
commInst(0x334, "@uvm.irbuilder.new_select")
commInst(0x335, "@uvm.irbuilder.new_branch")
commInst(0x336, "@uvm.irbuilder.new_branch2")
commInst(0x337, "@uvm.irbuilder.new_switch")
commInst(0x338, "@uvm.irbuilder.add_switch_dest")
commInst(0x339, "@uvm.irbuilder.new_call")
commInst(0x33a, "@uvm.irbuilder.new_tailcall")
commInst(0x33b, "@uvm.irbuilder.new_ret")
commInst(0x33c, "@uvm.irbuilder.new_throw")
commInst(0x33d, "@uvm.irbuilder.new_extractvalue")
commInst(0x33e, "@uvm.irbuilder.new_insertvalue")
commInst(0x33f, "@uvm.irbuilder.new_extractelement")
commInst(0x340, "@uvm.irbuilder.new_insertelement")
commInst(0x341, "@uvm.irbuilder.new_shufflevector")
commInst(0x342, "@uvm.irbuilder.new_new")
commInst(0x343, "@uvm.irbuilder.new_newhybrid")
commInst(0x344, "@uvm.irbuilder.new_alloca")
commInst(0x345, "@uvm.irbuilder.new_allocahybrid")
commInst(0x346, "@uvm.irbuilder.new_getiref")
commInst(0x347, "@uvm.irbuilder.new_getfieldiref")
commInst(0x348, "@uvm.irbuilder.new_getelemiref")
commInst(0x349, "@uvm.irbuilder.new_shiftiref")
commInst(0x34a, "@uvm.irbuilder.new_getvarpartiref")
commInst(0x34b, "@uvm.irbuilder.new_load")
commInst(0x34c, "@uvm.irbuilder.new_store")
commInst(0x34d, "@uvm.irbuilder.new_cmpxchg")
commInst(0x34e, "@uvm.irbuilder.new_atomicrmw")
commInst(0x34f, "@uvm.irbuilder.new_fence")
commInst(0x350, "@uvm.irbuilder.new_trap")
commInst(0x351, "@uvm.irbuilder.new_watchpoint")