1 #ifndef _RVMOPERATOR_H_
2 #define _RVMOPERATOR_H_
8 #define RVM_UNARY_HANDLER(__t__) (__t__)
9 #define RVM_OP_HANDLER(__ft__, __st__) ((__ft__) * RVM_DTYPE_MAX + (__st__))
12 #define RVM_OPID_NONE 0
13 #define RVM_OPID_ADD 1
14 #define RVM_OPID_SUB 2
15 #define RVM_OPID_MUL 3
16 #define RVM_OPID_DIV 4
17 #define RVM_OPID_CAT 5
20 * Important: the res pointer might be the same as one of the arguments, the operator must
21 * be implemented to take care of such cases.
23 typedef void (*rvm_unaryop_handler)(rvmcpu_t *cpu, rvmreg_t *res, const rvmreg_t *arg);
24 typedef void (*rvm_binaryop_handler)(rvmcpu_t *cpu, rvmreg_t *res, const rvmreg_t *arg1, const rvmreg_t *arg2);
26 typedef union rvm_ophandler_s {
27 rvm_unaryop_handler unary;
28 rvm_binaryop_handler op;
31 typedef struct rvm_opinfo_s {
34 rvm_ophandler_t *handlers;
37 typedef struct rvm_opmap_s {
42 rvm_opmap_t *rvm_opmap_create();
43 void rvm_opmap_destroy(rvm_opmap_t *opmap);
44 void rvm_opmap_add_binary_operator(rvm_opmap_t *opmap, rushort opid);
45 void rvm_opmap_add_unary_operator(rvm_opmap_t *opmap, rushort opid);
46 rint rvm_opmap_set_binary_handler(rvm_opmap_t *opmap, rushort opid, rvm_binaryop_handler func, ruchar firstType, ruchar secondType);
47 rint rvm_opmap_set_unary_handler(rvm_opmap_t *opmap, rushort opid, rvm_unaryop_handler func, ruchar type);
48 void rvm_opmap_invoke_binary_handler(rvm_opmap_t *opmap, rushort opid, rvmcpu_t *cpu, rvmreg_t *res, const rvmreg_t *arg1, const rvmreg_t *arg2);
49 void rvm_opmap_invoke_unary_handler(rvm_opmap_t *opmap, rushort opid, rvmcpu_t *cpu, rvmreg_t *res, const rvmreg_t *arg);