Commit 89f15c67 authored by Kunshan Wang's avatar Kunshan Wang

Replace new_inst_res with get_inst_res.

Given all arguments (including all type arguments, signature arguments
and value arguments), the micro VM always knows how many results an
instruction has.
parent f9f5b52c
......@@ -549,6 +549,8 @@ The canonical definition of each function is in the `IR Builder API
- ``MuFlag`` parameters, including its aliases such as ``MuBinOptr`` take the
same values as defined in the `<muapi.h>`__ header.
.. GEN:BEGIN:IRBUILDER_COMMINSTS
::
[0x300]@uvm.irbuilder.new_bundle () -> (irnoderef)
......@@ -589,56 +591,60 @@ The canonical definition of each function is in the `IR Builder API
[0x323]@uvm.irbuilder.new_const_double (%b: irnoderef, %ty: irnoderef, %value: double) -> (irnoderef)
[0x324]@uvm.irbuilder.new_const_null (%b: irnoderef, %ty: irnoderef) -> (irnoderef)
[0x325]@uvm.irbuilder.new_const_seq (%b: irnoderef, %ty: irnoderef, %elems: iref<irnoderef>, %nelems: int<64>) -> (irnoderef)
[0x326]@uvm.irbuilder.new_global_cell (%b: irnoderef, %ty: irnoderef) -> (irnoderef)
[0x327]@uvm.irbuilder.new_func (%b: irnoderef, %sig: irnoderef) -> (irnoderef)
[0x328]@uvm.irbuilder.new_func_ver (%b: irnoderef, %func: irnoderef) -> (irnoderef)
[0x329]@uvm.irbuilder.new_exp_func (%b: irnoderef, %func: irnoderef, %callconv: int<32>, %cookie: irnoderef) -> (irnoderef)
[0x32a]@uvm.irbuilder.new_bb (%fv: irnoderef) -> (irnoderef)
[0x32b]@uvm.irbuilder.new_nor_param (%bb: irnoderef, %ty: irnoderef) -> (irnoderef)
[0x32c]@uvm.irbuilder.new_exc_param (%bb: irnoderef) -> (irnoderef)
[0x32d]@uvm.irbuilder.new_inst_res (%inst: irnoderef) -> (irnoderef)
[0x32e]@uvm.irbuilder.add_dest (%inst: irnoderef, %kind: int<32>, %dest: irnoderef, %vars: iref<irnoderef>, %nvars: int<64>) -> ()
[0x32f]@uvm.irbuilder.add_keepalives (%inst: irnoderef, %vars: iref<irnoderef>, %nvars: int<64>) -> ()
[0x330]@uvm.irbuilder.new_binop (%bb: irnoderef, %optr: int<32>, %ty: irnoderef, %opnd1: irnoderef, %opnd2: irnoderef) -> (irnoderef)
[0x331]@uvm.irbuilder.new_cmp (%bb: irnoderef, %optr: int<32>, %ty: irnoderef, %opnd1: irnoderef, %opnd2: irnoderef) -> (irnoderef)
[0x332]@uvm.irbuilder.new_conv (%bb: irnoderef, %optr: int<32>, %from_ty: irnoderef, %to_ty: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x333]@uvm.irbuilder.new_select (%bb: irnoderef, %cond_ty: irnoderef, %opnd_ty: irnoderef, %cond: irnoderef, %if_true: irnoderef, %if_false: irnoderef) -> (irnoderef)
[0x334]@uvm.irbuilder.new_branch (%bb: irnoderef) -> (irnoderef)
[0x335]@uvm.irbuilder.new_branch2 (%bb: irnoderef, %cond: irnoderef) -> (irnoderef)
[0x336]@uvm.irbuilder.new_switch (%bb: irnoderef, %opnd_ty: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x337]@uvm.irbuilder.add_switch_dest (%sw: irnoderef, %key: irnoderef, %dest: irnoderef, %vars: iref<irnoderef>, %nvars: int<64>) -> ()
[0x338]@uvm.irbuilder.new_call (%bb: irnoderef, %sig: irnoderef, %callee: irnoderef, %args: iref<irnoderef>, %nargs: int<64>) -> (irnoderef)
[0x339]@uvm.irbuilder.new_tailcall (%bb: irnoderef, %sig: irnoderef, %callee: irnoderef, %args: iref<irnoderef>, %nargs: int<64>) -> (irnoderef)
[0x33a]@uvm.irbuilder.new_ret (%bb: irnoderef, %rvs: iref<irnoderef>, %nrvs: int<64>) -> (irnoderef)
[0x33b]@uvm.irbuilder.new_throw (%bb: irnoderef, %exc: irnoderef) -> (irnoderef)
[0x33c]@uvm.irbuilder.new_extractvalue (%bb: irnoderef, %strty: irnoderef, %index: int<32>, %opnd: irnoderef) -> (irnoderef)
[0x33d]@uvm.irbuilder.new_insertvalue (%bb: irnoderef, %strty: irnoderef, %index: int<32>, %opnd: irnoderef, %newval: irnoderef) -> (irnoderef)
[0x33e]@uvm.irbuilder.new_extractelement (%bb: irnoderef, %seqty: irnoderef, %indty: irnoderef, %opnd: irnoderef, %index: irnoderef) -> (irnoderef)
[0x33f]@uvm.irbuilder.new_insertelement (%bb: irnoderef, %seqty: irnoderef, %indty: irnoderef, %opnd: irnoderef, %index: irnoderef, %newval: irnoderef) -> (irnoderef)
[0x340]@uvm.irbuilder.new_shufflevector (%bb: irnoderef, %vecty: irnoderef, %maskty: irnoderef, %vec1: irnoderef, %vec2: irnoderef, %mask: irnoderef) -> (irnoderef)
[0x341]@uvm.irbuilder.new_new (%bb: irnoderef, %allocty: irnoderef) -> (irnoderef)
[0x342]@uvm.irbuilder.new_newhybrid (%bb: irnoderef, %allocty: irnoderef, %lenty: irnoderef, %length: irnoderef) -> (irnoderef)
[0x343]@uvm.irbuilder.new_alloca (%bb: irnoderef, %allocty: irnoderef) -> (irnoderef)
[0x344]@uvm.irbuilder.new_allocahybrid (%bb: irnoderef, %allocty: irnoderef, %lenty: irnoderef, %length: irnoderef) -> (irnoderef)
[0x345]@uvm.irbuilder.new_getiref (%bb: irnoderef, %refty: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x346]@uvm.irbuilder.new_getfieldiref (%bb: irnoderef, %is_ptr: int<32>, %refty: irnoderef, %index: int<32>, %opnd: irnoderef) -> (irnoderef)
[0x347]@uvm.irbuilder.new_getelemiref (%bb: irnoderef, %is_ptr: int<32>, %refty: irnoderef, %indty: irnoderef, %opnd: irnoderef, %index: irnoderef) -> (irnoderef)
[0x348]@uvm.irbuilder.new_shiftiref (%bb: irnoderef, %is_ptr: int<32>, %refty: irnoderef, %offty: irnoderef, %opnd: irnoderef, %offset: irnoderef) -> (irnoderef)
[0x349]@uvm.irbuilder.new_getvarpartiref (%bb: irnoderef, %is_ptr: int<32>, %refty: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x34a]@uvm.irbuilder.new_load (%bb: irnoderef, %is_ptr: int<32>, %ord: int<32>, %refty: irnoderef, %loc: irnoderef) -> (irnoderef)
[0x34b]@uvm.irbuilder.new_store (%bb: irnoderef, %is_ptr: int<32>, %ord: int<32>, %refty: irnoderef, %loc: irnoderef, %newval: irnoderef) -> (irnoderef)
[0x34c]@uvm.irbuilder.new_cmpxchg (%bb: irnoderef, %is_ptr: int<32>, %is_weak: int<32>, %ord_succ: int<32>, %ord_fail: int<32>, %refty: irnoderef, %loc: irnoderef, %expected: irnoderef, %desired: irnoderef) -> (irnoderef)
[0x34d]@uvm.irbuilder.new_atomicrmw (%bb: irnoderef, %is_ptr: int<32>, %ord: int<32>, %optr: int<32>, %refTy: irnoderef, %loc: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x34e]@uvm.irbuilder.new_fence (%bb: irnoderef, %ord: int<32>) -> (irnoderef)
[0x34f]@uvm.irbuilder.new_trap (%bb: irnoderef, %rettys: iref<irnoderef>, %nrettys: int<64>) -> (irnoderef)
[0x350]@uvm.irbuilder.new_watchpoint (%bb: irnoderef, %wpid: int<32>, %rettys: iref<irnoderef>, %nrettys: int<64>) -> (irnoderef)
[0x351]@uvm.irbuilder.new_wpbranch (%bb: irnoderef, %wpid: int<32>) -> (irnoderef)
[0x352]@uvm.irbuilder.new_ccall (%bb: irnoderef, %callconv: int<32>, %callee_ty: irnoderef, %sig: irnoderef, %callee: irnoderef, %args: iref<irnoderef>, %nargs: int<64>) -> (irnoderef)
[0x353]@uvm.irbuilder.new_newthread (%bb: irnoderef, %stack: irnoderef, %threadlocal: irnoderef) -> (irnoderef)
[0x354]@uvm.irbuilder.new_swapstack_ret (%bb: irnoderef, %swappee: irnoderef, %ret_tys: iref<irnoderef>, %nret_tys: int<64>) -> (irnoderef)
[0x355]@uvm.irbuilder.new_swapstack_kill (%bb: irnoderef, %swappee: irnoderef) -> (irnoderef)
[0x356]@uvm.irbuilder.set_newstack_pass_values (%inst: irnoderef, %tys: iref<irnoderef>, %vars: iref<irnoderef>, %nvars: int<64>) -> ()
[0x357]@uvm.irbuilder.set_newstack_throw_exc (%inst: irnoderef, %exc: irnoderef) -> ()
[0x358]@uvm.irbuilder.new_comminst (%bb: irnoderef, %opcode: int<32>, %flags: iref<int<32>>, %nflags: int<64>, %tys: iref<irnoderef>, %ntys: int<64>, %sigs: iref<irnoderef>, %nsigs: int<64>, %args: iref<irnoderef>, %nargs: int<64>) -> (irnoderef)
[0x326]@uvm.irbuilder.new_const_extern (%b: irnoderef, %ty: irnoderef, %symbol: iref<int<8>>) -> (irnoderef)
[0x327]@uvm.irbuilder.new_global_cell (%b: irnoderef, %ty: irnoderef) -> (irnoderef)
[0x328]@uvm.irbuilder.new_func (%b: irnoderef, %sig: irnoderef) -> (irnoderef)
[0x329]@uvm.irbuilder.new_func_ver (%b: irnoderef, %func: irnoderef) -> (irnoderef)
[0x32a]@uvm.irbuilder.new_exp_func (%b: irnoderef, %func: irnoderef, %callconv: int<32>, %cookie: irnoderef) -> (irnoderef)
[0x32b]@uvm.irbuilder.new_bb (%fv: irnoderef) -> (irnoderef)
[0x32c]@uvm.irbuilder.new_nor_param (%bb: irnoderef, %ty: irnoderef) -> (irnoderef)
[0x32d]@uvm.irbuilder.new_exc_param (%bb: irnoderef) -> (irnoderef)
[0x32e]@uvm.irbuilder.get_inst_res (%inst: irnoderef, %index: int<32>) -> (irnoderef)
[0x32f]@uvm.irbuilder.get_num_inst_res (%inst: irnoderef) -> (int<32>)
[0x330]@uvm.irbuilder.add_dest (%inst: irnoderef, %kind: int<32>, %dest: irnoderef, %vars: iref<irnoderef>, %nvars: int<64>) -> ()
[0x331]@uvm.irbuilder.add_keepalives (%inst: irnoderef, %vars: iref<irnoderef>, %nvars: int<64>) -> ()
[0x332]@uvm.irbuilder.new_binop (%bb: irnoderef, %optr: int<32>, %ty: irnoderef, %opnd1: irnoderef, %opnd2: irnoderef) -> (irnoderef)
[0x333]@uvm.irbuilder.new_cmp (%bb: irnoderef, %optr: int<32>, %ty: irnoderef, %opnd1: irnoderef, %opnd2: irnoderef) -> (irnoderef)
[0x334]@uvm.irbuilder.new_conv (%bb: irnoderef, %optr: int<32>, %from_ty: irnoderef, %to_ty: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x335]@uvm.irbuilder.new_select (%bb: irnoderef, %cond_ty: irnoderef, %opnd_ty: irnoderef, %cond: irnoderef, %if_true: irnoderef, %if_false: irnoderef) -> (irnoderef)
[0x336]@uvm.irbuilder.new_branch (%bb: irnoderef) -> (irnoderef)
[0x337]@uvm.irbuilder.new_branch2 (%bb: irnoderef, %cond: irnoderef) -> (irnoderef)
[0x338]@uvm.irbuilder.new_switch (%bb: irnoderef, %opnd_ty: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x339]@uvm.irbuilder.add_switch_dest (%sw: irnoderef, %key: irnoderef, %dest: irnoderef, %vars: iref<irnoderef>, %nvars: int<64>) -> ()
[0x33a]@uvm.irbuilder.new_call (%bb: irnoderef, %sig: irnoderef, %callee: irnoderef, %args: iref<irnoderef>, %nargs: int<64>) -> (irnoderef)
[0x33b]@uvm.irbuilder.new_tailcall (%bb: irnoderef, %sig: irnoderef, %callee: irnoderef, %args: iref<irnoderef>, %nargs: int<64>) -> (irnoderef)
[0x33c]@uvm.irbuilder.new_ret (%bb: irnoderef, %rvs: iref<irnoderef>, %nrvs: int<64>) -> (irnoderef)
[0x33d]@uvm.irbuilder.new_throw (%bb: irnoderef, %exc: irnoderef) -> (irnoderef)
[0x33e]@uvm.irbuilder.new_extractvalue (%bb: irnoderef, %strty: irnoderef, %index: int<32>, %opnd: irnoderef) -> (irnoderef)
[0x33f]@uvm.irbuilder.new_insertvalue (%bb: irnoderef, %strty: irnoderef, %index: int<32>, %opnd: irnoderef, %newval: irnoderef) -> (irnoderef)
[0x340]@uvm.irbuilder.new_extractelement (%bb: irnoderef, %seqty: irnoderef, %indty: irnoderef, %opnd: irnoderef, %index: irnoderef) -> (irnoderef)
[0x341]@uvm.irbuilder.new_insertelement (%bb: irnoderef, %seqty: irnoderef, %indty: irnoderef, %opnd: irnoderef, %index: irnoderef, %newval: irnoderef) -> (irnoderef)
[0x342]@uvm.irbuilder.new_shufflevector (%bb: irnoderef, %vecty: irnoderef, %maskty: irnoderef, %vec1: irnoderef, %vec2: irnoderef, %mask: irnoderef) -> (irnoderef)
[0x343]@uvm.irbuilder.new_new (%bb: irnoderef, %allocty: irnoderef) -> (irnoderef)
[0x344]@uvm.irbuilder.new_newhybrid (%bb: irnoderef, %allocty: irnoderef, %lenty: irnoderef, %length: irnoderef) -> (irnoderef)
[0x345]@uvm.irbuilder.new_alloca (%bb: irnoderef, %allocty: irnoderef) -> (irnoderef)
[0x346]@uvm.irbuilder.new_allocahybrid (%bb: irnoderef, %allocty: irnoderef, %lenty: irnoderef, %length: irnoderef) -> (irnoderef)
[0x347]@uvm.irbuilder.new_getiref (%bb: irnoderef, %refty: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x348]@uvm.irbuilder.new_getfieldiref (%bb: irnoderef, %is_ptr: int<32>, %refty: irnoderef, %index: int<32>, %opnd: irnoderef) -> (irnoderef)
[0x349]@uvm.irbuilder.new_getelemiref (%bb: irnoderef, %is_ptr: int<32>, %refty: irnoderef, %indty: irnoderef, %opnd: irnoderef, %index: irnoderef) -> (irnoderef)
[0x34a]@uvm.irbuilder.new_shiftiref (%bb: irnoderef, %is_ptr: int<32>, %refty: irnoderef, %offty: irnoderef, %opnd: irnoderef, %offset: irnoderef) -> (irnoderef)
[0x34b]@uvm.irbuilder.new_getvarpartiref (%bb: irnoderef, %is_ptr: int<32>, %refty: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x34c]@uvm.irbuilder.new_load (%bb: irnoderef, %is_ptr: int<32>, %ord: int<32>, %refty: irnoderef, %loc: irnoderef) -> (irnoderef)
[0x34d]@uvm.irbuilder.new_store (%bb: irnoderef, %is_ptr: int<32>, %ord: int<32>, %refty: irnoderef, %loc: irnoderef, %newval: irnoderef) -> (irnoderef)
[0x34e]@uvm.irbuilder.new_cmpxchg (%bb: irnoderef, %is_ptr: int<32>, %is_weak: int<32>, %ord_succ: int<32>, %ord_fail: int<32>, %refty: irnoderef, %loc: irnoderef, %expected: irnoderef, %desired: irnoderef) -> (irnoderef)
[0x34f]@uvm.irbuilder.new_atomicrmw (%bb: irnoderef, %is_ptr: int<32>, %ord: int<32>, %optr: int<32>, %refTy: irnoderef, %loc: irnoderef, %opnd: irnoderef) -> (irnoderef)
[0x350]@uvm.irbuilder.new_fence (%bb: irnoderef, %ord: int<32>) -> (irnoderef)
[0x351]@uvm.irbuilder.new_trap (%bb: irnoderef, %rettys: iref<irnoderef>, %nrettys: int<64>) -> (irnoderef)
[0x352]@uvm.irbuilder.new_watchpoint (%bb: irnoderef, %wpid: int<32>, %rettys: iref<irnoderef>, %nrettys: int<64>) -> (irnoderef)
[0x353]@uvm.irbuilder.new_wpbranch (%bb: irnoderef, %wpid: int<32>) -> (irnoderef)
[0x354]@uvm.irbuilder.new_ccall (%bb: irnoderef, %callconv: int<32>, %callee_ty: irnoderef, %sig: irnoderef, %callee: irnoderef, %args: iref<irnoderef>, %nargs: int<64>) -> (irnoderef)
[0x355]@uvm.irbuilder.new_newthread (%bb: irnoderef, %stack: irnoderef, %threadlocal: irnoderef) -> (irnoderef)
[0x356]@uvm.irbuilder.new_swapstack_ret (%bb: irnoderef, %swappee: irnoderef, %ret_tys: iref<irnoderef>, %nret_tys: int<64>) -> (irnoderef)
[0x357]@uvm.irbuilder.new_swapstack_kill (%bb: irnoderef, %swappee: irnoderef) -> (irnoderef)
[0x358]@uvm.irbuilder.set_newstack_pass_values (%inst: irnoderef, %tys: iref<irnoderef>, %vars: iref<irnoderef>, %nvars: int<64>) -> ()
[0x359]@uvm.irbuilder.set_newstack_throw_exc (%inst: irnoderef, %exc: irnoderef) -> ()
[0x35a]@uvm.irbuilder.new_comminst (%bb: irnoderef, %opcode: int<32>, %flags: iref<int<32>>, %nflags: int<64>, %tys: iref<irnoderef>, %ntys: int<64>, %sigs: iref<irnoderef>, %nsigs: int<64>, %args: iref<irnoderef>, %nargs: int<64>) -> (irnoderef)
.. GEN:END:IRBUILDER_COMMINSTS
.. vim: tw=80
......@@ -204,20 +204,22 @@ defining it.
MuNorParam p0 = ctx->new_nor_param(ctx, entry, i32);
MuNorParam p1 = ctx->new_nor_param(ctx, entry, i32);
**Instructions** can be added to basic blocks. NOTE that the **results of
instructions are separate IR nodes**! They have to be added separately::
**Instructions** can be added to basic blocks. Each instruction may have zero or
more results. **Instruction results** are IR nodes, too. They are created when
the instruction is created. Their handles can be obtained by the
``get_inst_res`` function::
// The ADD instruction produces one result.
MuInstNode add = ctx->new_binop(ctx, entry, MU_BINOP_ADD, i32, p0, p1);
MuInstResNode add_r = ctx->new_inst_res(ctx, add);
MuInstResNode add_r = ctx->get_inst_res(ctx, add, 0);
// Mu functions may return multiple return values.
MuVarNode args[] = { xxx, xxx, xxx };
MuInstNode call = ctx->new_call(ctx, entry, some_sig, some_func, args, 3);
MuInstResNode call_r0 = ctx->new_inst_res(ctx, call);
MuInstResNode call_r1 = ctx->new_inst_res(ctx, call);
MuInstResNode call_r2 = ctx->new_inst_res(ctx, call);
MuInstResNode call_r3 = ctx->new_inst_res(ctx, call);
MuInstResNode call_r0 = ctx->get_inst_res(ctx, call, 0);
MuInstResNode call_r1 = ctx->get_inst_res(ctx, call, 1);
MuInstResNode call_r2 = ctx->get_inst_res(ctx, call, 2);
MuInstResNode call_r3 = ctx->get_inst_res(ctx, call, 3);
Unlike the text form, the **exception clauses** are just destinations. For
instructions that may have exception clauses, if you set the normal destination,
......@@ -502,11 +504,15 @@ function, or redefine an existing function, the client should use the
::
MuInstResNode (*new_inst_res )(MuCtx *ctx, MuInstNode inst);
MuInstResNode (*get_inst_res )(MuCtx *ctx, MuInstNode inst, int index);
int (*get_num_inst_res)(MuCtx *ctx, MuInstNode inst);
``new_inst_res`` creates an instruction result node and adds it to the
instruction ``inst``. Each instruction must have **exactly** as many result
nodes as the number of results it produces.
``get_inst_res`` gets the ``index``-th instruction result node from the
instruction ``inst``. ``index`` starts from 0. This function returns a new
handle for each call (but refers to the same *IR node*), so they need to be
disposed (``delete_value``) separately, or just close the ``MuCtx``.
``get_num_inst_res`` gets the number of results of the instruction ``inst``.
.. _add_dest:
......
......@@ -551,8 +551,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.
......@@ -624,7 +625,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
......@@ -706,58 +707,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
}
......
#/usr/bin/env python3
"""
Extract comminst definitions from common-insts.rst into C macros.
USAGE: python3 script/comminsts-to-muapi.py
"""
import re
import sys
from muspecinjectablefiles import injectable_files, common_insts_path
pat = re.compile(r'\[(0x[0-9a-f]+)\]@([a-zA-Z0-9_.]+)', re.MULTILINE)
def main():
defs = []
longest = 0
with open(common_insts_path) as f:
text = f.read()
for opcode, name in pat.findall(text):
macro_name = "MU_CI_" + name.upper().replace(".", "_")
opcode = opcode.lower()
defs.append((name, macro_name, opcode))
longest = max(longest, len(macro_name))
lines = []
for name, macro_name, opcode in defs:
lines.append("#define {} ((MuCommInst){}) /// MUAPIPARSER muname:@{}".format(
macro_name.ljust(longest), opcode, name))
outtext = "\n".join(lines)
injectable_files["muapi.h"].inject_many({
"COMMINSTS": outtext,
})
if __name__=="__main__":
main()
#/usr/bin/env python3
"""
Extract comminst definitions from common-insts.rest into C macros.
USAGE: python3 script/extract_comminst_macros.py < common-inst.rest
"""
import re
import sys
pat = re.compile(r'\[(0x[0-9a-f]+)\]@([a-zA-Z0-9_.]+)', re.MULTILINE)
defs = []
longest = 0
text = sys.stdin.read()
for opcode, name in pat.findall(text):
macro_name = "MU_CI_" + name.upper().replace(".", "_")
opcode = opcode.lower()
defs.append((name, macro_name, opcode))
longest = max(longest, len(macro_name))
for name, macro_name, opcode in defs:
print("#define {} ((MuCommInst){}) /// MUAPIPARSER muname:@{}".format(
macro_name.ljust(longest), opcode, name))
import re
from typing import List, Union, Tuple, Any, Callable, TypeVar
from typing import List, Union, Tuple, Any, Callable, TypeVar, Mapping
from typing.re import Pattern
import tempfile, os.path
Predicate = Union[str,
Tuple[Pattern, ...],
Callable[[Any], bool]]
......@@ -62,3 +64,56 @@ def inject_lines(parent: str, begin: Predicate, end: Predicate, generated: str)
new_lines = lines[:begin_line+1] + generated.splitlines() + lines[end_line:]
return "\n".join(new_lines)
STANDARD_PREFIX_BEGIN = "GEN:BEGIN:"
STANDARD_PREFIX_END = "GEN:END:"
class StandardInjectableFile(object):
def __init__(self, path: str, injection_points: List[str] = None):
self.path = path
if injection_points is None:
injection_points = []
self.injection_points = injection_points
def inject_many(self, m: Mapping[str, str], force=False):
with open(self.path) as f:
orig_txt = f.read()
txt = orig_txt
for inj_point, inj_content in m.items():
if inj_point not in self.injection_points and not force:
raise Exception("Unknown injection point '{}'".format(inj_point))
inj_begin = STANDARD_PREFIX_BEGIN + inj_point
inj_end = STANDARD_PREFIX_END + inj_point
new_txt = inject_lines(txt, inj_begin, inj_end, inj_content)
txt = new_txt
if not txt.endswith("\n"):
txt += "\n"
with tempfile.NamedTemporaryFile("w", delete=False) as f:
print("Backup to temporary file: {} -> {}".format(self.path, f.name))
f.write(orig_txt)
with open(self.path, "w") as f:
print("Writing to file: {}".format(self.path))
f.write(txt)
def make_injectable_file_set(
root_path: str,
items : List[Tuple[str, str, List[str]]],
) -> Mapping[str, StandardInjectableFile]:
m = InjectableFileSet()
for name, path, inj_points in items:
full_path = os.path.join(root_path, path)
sif = StandardInjectableFile(full_path, inj_points)
m[name] = sif
return m
class InjectableFileSet(dict):
def inject_many(self, m: Mapping[str, Mapping[str, str]]):
for name, mm in m.items():
self[name].inject_many(mm)
......@@ -9,6 +9,8 @@ Then paste into common-insts.rst
import muapiparser
import sys
from muspecinjectablefiles import injectable_files, muapi_h_path
start_id_comminst = 0x300
start_id_constant = 0x400
......@@ -16,6 +18,7 @@ _type_map = {
"void" : "",
"MuID" : "int<32>",
"MuName" : "iref<int<8>>",
"MuCString" : "iref<int<8>>",
"MuBool" : "int<32>",
"MuWPID" : "int<32>",
"MuArraySize" : "int<64>",
......@@ -54,7 +57,7 @@ def to_mu_ty(cty):
else:
raise Exception("I don't know how to translate: {}".format(cty))
def print_comminsts(ast):
def get_comminst_defs(ast):
muctx_methods = [s["methods"] for s in ast["structs"]
if s["name"] == "MuCtx"][0]
......@@ -64,6 +67,8 @@ def print_comminsts(ast):
next_id = start_id_comminst
lines = ["", "::", ""] # start reStructuredText block
for i in range(index_new_bundle, len(muctx_methods)):
meth = muctx_methods[i]
name = meth["name"]
......@@ -83,11 +88,16 @@ def print_comminsts(ast):
mu_params_joined = ", ".join(mu_params)
mu_ret_ty = to_mu_ty(ret_ty)
print(" [0x{:x}]@uvm.irbuilder.{} ({}) -> ({})".format(
lines.append(" [0x{:x}]@uvm.irbuilder.{} ({}) -> ({})".format(
next_id, name, mu_params_joined, mu_ret_ty))
next_id += 1
lines.append("")
lines.append("")
return "\n".join(lines)
_enums = [
"MuDestKind",
"MuBinOptr",
......@@ -99,43 +109,17 @@ _enums = [
"MuCommInst",
]
def print_constants(ast):
""" NOT USED """
enums = ast["enums"]
next_id = start_id_constant
enums_map = {}
for enum in enums:
enums_map[enum["name"]] = enum["defs"]
print(" .typedef @uvm.irbuilder.MuFlag = int<32> // Private. Not available for the client.")
for enum_name in _enums:
defs = enums_map[enum_name]
for def_ in defs:
cn = def_["name"]
cv = def_["value"]
mcn = "@uvm.irbuilder." + cn
mcv = cv
print(" .const {} <@uvm.irbuilder.MuFlag> = {} // ID: 0x{:x}".format(
mcn, mcv, next_id))
next_id += 1
def main():
txt = sys.stdin.read()
with open(muapi_h_path) as f:
txt = f.read()
ast = muapiparser.parse_muapi(txt)
print_comminsts(ast)
#print()
#print_constants(ast) # Do not print. This merely pollutes the pre-loaded
# space with more constants, and not profitable.
# We keep muapi.h as the canonical definition.
# Clients should define their own constants.
outtext = get_comminst_defs(ast)
injectable_files["common-insts.rst"].inject_many({
"IRBUILDER_COMMINSTS": outtext,
})
if __name__=='__main__':
main()
import injecttools
import os.path
_my_dir = os.path.dirname(__file__)
_mu_spec_root = os.path.join(_my_dir, "..")
def _make_injectable_file_set(m):
m2 = {os.path.join(_mu_spec_root, k): v for k,v in m.items()}
return InjectableFileSet(m2)
muapi_h_path = os.path.join(_mu_spec_root, "muapi.h")
common_insts_path = os.path.join(_mu_spec_root, "common-insts.rst")
injectable_files = injecttools.make_injectable_file_set(_mu_spec_root, [
("common-insts.rst", "common-insts.rst",
["IRBUILDER_COMMINSTS"]),
("muapi.h", "muapi.h",
["COMMINSTS"]),
])
python3 muapi-irbuilder-to-comminsts.py
python3 comminsts-to-muapi.py
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