Skip to content

Commit

Permalink
Split RzAnalysisOpType in a different file
Browse files Browse the repository at this point in the history
    * This way, files like `librz/util/print.c` and `Colors.cpp` in
      Cutter don't need to include the entire `rz_analysis.h`, but only
      need to include `rz_analysis_optype.h`
  • Loading branch information
DMaroo committed Sep 20, 2023
1 parent 0bbec47 commit 4a9e550
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 91 deletions.
4 changes: 2 additions & 2 deletions librz/analysis/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static struct optype {
/**
* Return the op type corresponding the given name
* \param name string, name of the optype
* \return type int, id of the op type (one of \link _RzAnalysisOpType \endlink)
* \return type int, id of the op type (one of \link RzAnalysisOpType \endlink)
*/
RZ_API int rz_analysis_optype_from_string(RZ_NONNULL const char *name) {
rz_return_val_if_fail(name, -1);
Expand All @@ -305,7 +305,7 @@ RZ_API int rz_analysis_optype_from_string(RZ_NONNULL const char *name) {

/**
* Return the name of the given op type
* \param type int, id of the op type (one of \link _RzAnalysisOpType \endlink)
* \param type int, id of the op type (one of \link RzAnalysisOpType \endlink)
* \return name string, string, name of the optype
*/
RZ_API const char *rz_analysis_optype_to_string(int type) {
Expand Down
2 changes: 1 addition & 1 deletion librz/asm/arch/8051/8051_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ typedef struct {
ut8 op;
int cycles;
op8051 instr; // instruction
_RzAnalysisOpType type;
RzAnalysisOpType type;
char *string; // disassembly output
size_t len;
argmask8051 mask; // bits masked to determine opcode
Expand Down
2 changes: 1 addition & 1 deletion librz/asm/arch/hexagon/hexagon_disas.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ typedef struct {
ut8 cond; // RzTypeCond
ut8 flags; // HexInsnTemplateFlag
const char *syntax;
_RzAnalysisOpType type;
RzAnalysisOpType type;
} HexInsnTemplate;

static const HexInsnTemplate templates_sub_A[] = {
Expand Down
4 changes: 2 additions & 2 deletions librz/asm/arch/or1k/or1k_disas.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ typedef struct {
char *name;
int type;
int opcode_mask;
int insn_type; /**< One of \link _RzAnalysisOpType \endlink */
int insn_type; /**< One of \link RzAnalysisOpType \endlink */
} insn_extra_t;

typedef struct {
ut32 opcode;
char *name;
int type;
int insn_type; /**< One of \link _RzAnalysisOpType \endlink */
int insn_type; /**< One of \link RzAnalysisOpType \endlink */
insn_extra_t *extra;
} insn_t;

Expand Down
84 changes: 1 addition & 83 deletions librz/include/rz_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <rz_il.h>
#include <rz_platform.h>
#include <rz_cmd.h>
#include <rz_analysis_optype.h>

#define esilprintf(op, fmt, ...) rz_strbuf_setf(&op->esil, fmt, ##__VA_ARGS__)

Expand Down Expand Up @@ -254,89 +255,6 @@ typedef enum {
/* TODO: add segment override typemods? */
} RzAnalysisOpPrefix;

// XXX: this definition is plain wrong. use enum or empower bits
#define RZ_ANALYSIS_OP_TYPE_MASK 0x8000ffff
#define RZ_ANALYSIS_OP_HINT_MASK 0xf0000000
typedef enum {
RZ_ANALYSIS_OP_TYPE_COND = 0x80000000, // TODO must be moved to prefix?
// TODO: MOVE TO PREFIX .. it is used by analysis_java.. must be updated
RZ_ANALYSIS_OP_TYPE_REP = 0x40000000, /* repeats next instruction N times */
RZ_ANALYSIS_OP_TYPE_MEM = 0x20000000, // TODO must be moved to prefix?
RZ_ANALYSIS_OP_TYPE_REG = 0x10000000, // operand is a register
RZ_ANALYSIS_OP_TYPE_IND = 0x08000000, // operand is indirect
RZ_ANALYSIS_OP_TYPE_SIMD = 0x04000000, // SIMD
RZ_ANALYSIS_OP_TYPE_NULL = 0,
RZ_ANALYSIS_OP_TYPE_JMP = 1, /* mandatory jump */
RZ_ANALYSIS_OP_TYPE_UJMP = 2, /* unknown jump (register or so) */
RZ_ANALYSIS_OP_TYPE_RJMP = RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_UJMP,
RZ_ANALYSIS_OP_TYPE_IJMP = RZ_ANALYSIS_OP_TYPE_IND | RZ_ANALYSIS_OP_TYPE_UJMP,
RZ_ANALYSIS_OP_TYPE_IRJMP = RZ_ANALYSIS_OP_TYPE_IND | RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_UJMP,
RZ_ANALYSIS_OP_TYPE_CJMP = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_JMP, /* conditional jump */
RZ_ANALYSIS_OP_TYPE_RCJMP = RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_CJMP, /* conditional jump register */
RZ_ANALYSIS_OP_TYPE_MJMP = RZ_ANALYSIS_OP_TYPE_MEM | RZ_ANALYSIS_OP_TYPE_JMP, /* memory jump */
RZ_ANALYSIS_OP_TYPE_MCJMP = RZ_ANALYSIS_OP_TYPE_MEM | RZ_ANALYSIS_OP_TYPE_CJMP, /* memory conditional jump */
RZ_ANALYSIS_OP_TYPE_UCJMP = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_UJMP, /* conditional unknown jump */
RZ_ANALYSIS_OP_TYPE_CALL = 3, /* call to subroutine (branch+link) */
RZ_ANALYSIS_OP_TYPE_UCALL = 4, /* unknown call (register or so) */
RZ_ANALYSIS_OP_TYPE_RCALL = RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_UCALL,
RZ_ANALYSIS_OP_TYPE_ICALL = RZ_ANALYSIS_OP_TYPE_IND | RZ_ANALYSIS_OP_TYPE_UCALL,
RZ_ANALYSIS_OP_TYPE_IRCALL = RZ_ANALYSIS_OP_TYPE_IND | RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_UCALL,
RZ_ANALYSIS_OP_TYPE_CCALL = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_CALL, /* conditional call to subroutine */
RZ_ANALYSIS_OP_TYPE_UCCALL = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_UCALL, /* conditional unknown call */
RZ_ANALYSIS_OP_TYPE_RET = 5, /* returns from subroutine */
RZ_ANALYSIS_OP_TYPE_CRET = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_RET, /* conditional return from subroutine */
RZ_ANALYSIS_OP_TYPE_ILL = 6, /* illegal instruction // trap */
RZ_ANALYSIS_OP_TYPE_UNK = 7, /* unknown opcode type */
RZ_ANALYSIS_OP_TYPE_NOP = 8, /* does nothing */
RZ_ANALYSIS_OP_TYPE_MOV = 9, /* register move */
RZ_ANALYSIS_OP_TYPE_CMOV = 9 | RZ_ANALYSIS_OP_TYPE_COND, /* conditional move */
RZ_ANALYSIS_OP_TYPE_TRAP = 10, /* it's a trap! */
RZ_ANALYSIS_OP_TYPE_SWI = 11, /* syscall, software interrupt */
RZ_ANALYSIS_OP_TYPE_CSWI = 11 | RZ_ANALYSIS_OP_TYPE_COND, /* syscall, software interrupt */
RZ_ANALYSIS_OP_TYPE_UPUSH = 12, /* unknown push of data into stack */
RZ_ANALYSIS_OP_TYPE_RPUSH = RZ_ANALYSIS_OP_TYPE_UPUSH | RZ_ANALYSIS_OP_TYPE_REG, /* push register */
RZ_ANALYSIS_OP_TYPE_PUSH = 13, /* push value into stack */
RZ_ANALYSIS_OP_TYPE_POP = 14, /* pop value from stack to register */
RZ_ANALYSIS_OP_TYPE_CMP = 15, /* compare something */
RZ_ANALYSIS_OP_TYPE_ACMP = 16, /* compare via and */
RZ_ANALYSIS_OP_TYPE_ADD = 17,
RZ_ANALYSIS_OP_TYPE_SUB = 18,
RZ_ANALYSIS_OP_TYPE_IO = 19,
RZ_ANALYSIS_OP_TYPE_MUL = 20,
RZ_ANALYSIS_OP_TYPE_DIV = 21,
RZ_ANALYSIS_OP_TYPE_SHR = 22,
RZ_ANALYSIS_OP_TYPE_SHL = 23,
RZ_ANALYSIS_OP_TYPE_SAL = 24,
RZ_ANALYSIS_OP_TYPE_SAR = 25,
RZ_ANALYSIS_OP_TYPE_OR = 26,
RZ_ANALYSIS_OP_TYPE_AND = 27,
RZ_ANALYSIS_OP_TYPE_XOR = 28,
RZ_ANALYSIS_OP_TYPE_NOR = 29,
RZ_ANALYSIS_OP_TYPE_NOT = 30,
RZ_ANALYSIS_OP_TYPE_STORE = 31, /* store from register to memory */
RZ_ANALYSIS_OP_TYPE_LOAD = 32, /* load from memory to register */
RZ_ANALYSIS_OP_TYPE_LEA = 33, /* TODO add ulea */
RZ_ANALYSIS_OP_TYPE_LEAVE = 34,
RZ_ANALYSIS_OP_TYPE_ROR = 35,
RZ_ANALYSIS_OP_TYPE_ROL = 36,
RZ_ANALYSIS_OP_TYPE_XCHG = 37,
RZ_ANALYSIS_OP_TYPE_MOD = 38,
RZ_ANALYSIS_OP_TYPE_SWITCH = 39,
RZ_ANALYSIS_OP_TYPE_CASE = 40,
RZ_ANALYSIS_OP_TYPE_LENGTH = 41,
RZ_ANALYSIS_OP_TYPE_CAST = 42,
RZ_ANALYSIS_OP_TYPE_NEW = 43,
RZ_ANALYSIS_OP_TYPE_ABS = 44,
RZ_ANALYSIS_OP_TYPE_CPL = 45, /* complement */
RZ_ANALYSIS_OP_TYPE_CRYPTO = 46,
RZ_ANALYSIS_OP_TYPE_SYNC = 47,
// RZ_ANALYSIS_OP_TYPE_DEBUG = 43, // monitor/trace/breakpoint
#if 0
RZ_ANALYSIS_OP_TYPE_PRIV = 40, /* privileged instruction */
RZ_ANALYSIS_OP_TYPE_FPU = 41, /* floating point stuff */
#endif
} _RzAnalysisOpType;

typedef enum {
RZ_ANALYSIS_OP_MASK_BASIC = 0, // Just fills basic op info , it's fast
RZ_ANALYSIS_OP_MASK_ESIL = (1 << 0), // It fills RzAnalysisop->esil info
Expand Down
88 changes: 88 additions & 0 deletions librz/include/rz_analysis_optype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef RZ_ANALYSIS_OPTYPE_H
#define RZ_ANALYSIS_OPTYPE_H

// XXX: this definition is plain wrong. use enum or empower bits
#define RZ_ANALYSIS_OP_TYPE_MASK 0x8000ffff
#define RZ_ANALYSIS_OP_HINT_MASK 0xf0000000

typedef enum {
RZ_ANALYSIS_OP_TYPE_COND = 0x80000000, // TODO must be moved to prefix?
// TODO: MOVE TO PREFIX .. it is used by analysis_java.. must be updated
RZ_ANALYSIS_OP_TYPE_REP = 0x40000000, /* repeats next instruction N times */
RZ_ANALYSIS_OP_TYPE_MEM = 0x20000000, // TODO must be moved to prefix?
RZ_ANALYSIS_OP_TYPE_REG = 0x10000000, // operand is a register
RZ_ANALYSIS_OP_TYPE_IND = 0x08000000, // operand is indirect
RZ_ANALYSIS_OP_TYPE_SIMD = 0x04000000, // SIMD
RZ_ANALYSIS_OP_TYPE_NULL = 0,
RZ_ANALYSIS_OP_TYPE_JMP = 1, /* mandatory jump */
RZ_ANALYSIS_OP_TYPE_UJMP = 2, /* unknown jump (register or so) */
RZ_ANALYSIS_OP_TYPE_RJMP = RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_UJMP,
RZ_ANALYSIS_OP_TYPE_IJMP = RZ_ANALYSIS_OP_TYPE_IND | RZ_ANALYSIS_OP_TYPE_UJMP,
RZ_ANALYSIS_OP_TYPE_IRJMP = RZ_ANALYSIS_OP_TYPE_IND | RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_UJMP,
RZ_ANALYSIS_OP_TYPE_CJMP = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_JMP, /* conditional jump */
RZ_ANALYSIS_OP_TYPE_RCJMP = RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_CJMP, /* conditional jump register */
RZ_ANALYSIS_OP_TYPE_MJMP = RZ_ANALYSIS_OP_TYPE_MEM | RZ_ANALYSIS_OP_TYPE_JMP, /* memory jump */
RZ_ANALYSIS_OP_TYPE_MCJMP = RZ_ANALYSIS_OP_TYPE_MEM | RZ_ANALYSIS_OP_TYPE_CJMP, /* memory conditional jump */
RZ_ANALYSIS_OP_TYPE_UCJMP = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_UJMP, /* conditional unknown jump */
RZ_ANALYSIS_OP_TYPE_CALL = 3, /* call to subroutine (branch+link) */
RZ_ANALYSIS_OP_TYPE_UCALL = 4, /* unknown call (register or so) */
RZ_ANALYSIS_OP_TYPE_RCALL = RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_UCALL,
RZ_ANALYSIS_OP_TYPE_ICALL = RZ_ANALYSIS_OP_TYPE_IND | RZ_ANALYSIS_OP_TYPE_UCALL,
RZ_ANALYSIS_OP_TYPE_IRCALL = RZ_ANALYSIS_OP_TYPE_IND | RZ_ANALYSIS_OP_TYPE_REG | RZ_ANALYSIS_OP_TYPE_UCALL,
RZ_ANALYSIS_OP_TYPE_CCALL = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_CALL, /* conditional call to subroutine */
RZ_ANALYSIS_OP_TYPE_UCCALL = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_UCALL, /* conditional unknown call */
RZ_ANALYSIS_OP_TYPE_RET = 5, /* returns from subroutine */
RZ_ANALYSIS_OP_TYPE_CRET = RZ_ANALYSIS_OP_TYPE_COND | RZ_ANALYSIS_OP_TYPE_RET, /* conditional return from subroutine */
RZ_ANALYSIS_OP_TYPE_ILL = 6, /* illegal instruction // trap */
RZ_ANALYSIS_OP_TYPE_UNK = 7, /* unknown opcode type */
RZ_ANALYSIS_OP_TYPE_NOP = 8, /* does nothing */
RZ_ANALYSIS_OP_TYPE_MOV = 9, /* register move */
RZ_ANALYSIS_OP_TYPE_CMOV = 9 | RZ_ANALYSIS_OP_TYPE_COND, /* conditional move */
RZ_ANALYSIS_OP_TYPE_TRAP = 10, /* it's a trap! */
RZ_ANALYSIS_OP_TYPE_SWI = 11, /* syscall, software interrupt */
RZ_ANALYSIS_OP_TYPE_CSWI = 11 | RZ_ANALYSIS_OP_TYPE_COND, /* syscall, software interrupt */
RZ_ANALYSIS_OP_TYPE_UPUSH = 12, /* unknown push of data into stack */
RZ_ANALYSIS_OP_TYPE_RPUSH = RZ_ANALYSIS_OP_TYPE_UPUSH | RZ_ANALYSIS_OP_TYPE_REG, /* push register */
RZ_ANALYSIS_OP_TYPE_PUSH = 13, /* push value into stack */
RZ_ANALYSIS_OP_TYPE_POP = 14, /* pop value from stack to register */
RZ_ANALYSIS_OP_TYPE_CMP = 15, /* compare something */
RZ_ANALYSIS_OP_TYPE_ACMP = 16, /* compare via and */
RZ_ANALYSIS_OP_TYPE_ADD = 17,
RZ_ANALYSIS_OP_TYPE_SUB = 18,
RZ_ANALYSIS_OP_TYPE_IO = 19,
RZ_ANALYSIS_OP_TYPE_MUL = 20,
RZ_ANALYSIS_OP_TYPE_DIV = 21,
RZ_ANALYSIS_OP_TYPE_SHR = 22,
RZ_ANALYSIS_OP_TYPE_SHL = 23,
RZ_ANALYSIS_OP_TYPE_SAL = 24,
RZ_ANALYSIS_OP_TYPE_SAR = 25,
RZ_ANALYSIS_OP_TYPE_OR = 26,
RZ_ANALYSIS_OP_TYPE_AND = 27,
RZ_ANALYSIS_OP_TYPE_XOR = 28,
RZ_ANALYSIS_OP_TYPE_NOR = 29,
RZ_ANALYSIS_OP_TYPE_NOT = 30,
RZ_ANALYSIS_OP_TYPE_STORE = 31, /* store from register to memory */
RZ_ANALYSIS_OP_TYPE_LOAD = 32, /* load from memory to register */
RZ_ANALYSIS_OP_TYPE_LEA = 33, /* TODO add ulea */
RZ_ANALYSIS_OP_TYPE_LEAVE = 34,
RZ_ANALYSIS_OP_TYPE_ROR = 35,
RZ_ANALYSIS_OP_TYPE_ROL = 36,
RZ_ANALYSIS_OP_TYPE_XCHG = 37,
RZ_ANALYSIS_OP_TYPE_MOD = 38,
RZ_ANALYSIS_OP_TYPE_SWITCH = 39,
RZ_ANALYSIS_OP_TYPE_CASE = 40,
RZ_ANALYSIS_OP_TYPE_LENGTH = 41,
RZ_ANALYSIS_OP_TYPE_CAST = 42,
RZ_ANALYSIS_OP_TYPE_NEW = 43,
RZ_ANALYSIS_OP_TYPE_ABS = 44,
RZ_ANALYSIS_OP_TYPE_CPL = 45, /* complement */
RZ_ANALYSIS_OP_TYPE_CRYPTO = 46,
RZ_ANALYSIS_OP_TYPE_SYNC = 47,
// RZ_ANALYSIS_OP_TYPE_DEBUG = 43, // monitor/trace/breakpoint
#if 0
RZ_ANALYSIS_OP_TYPE_PRIV = 40, /* privileged instruction */
RZ_ANALYSIS_OP_TYPE_FPU = 41, /* floating point stuff */
#endif
} RzAnalysisOpType;

#endif // RZ_ANALYSIS_OPTYPE_H
2 changes: 1 addition & 1 deletion librz/include/rz_util/rz_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ typedef struct {

typedef struct {
const RzRegSet *reg_sets; ///< Array of reg sets used to lookup register names during parsing.
ut32 ana_op_type; ///< Analysis op type (see: _RzAnalysisOpType) of the token string to parse.
ut32 ana_op_type; ///< Analysis op type (see: RzAnalysisOpType) of the token string to parse.
} RzAsmParseParam;

/**
Expand Down
2 changes: 1 addition & 1 deletion librz/util/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <rz_util/rz_strbuf.h>
#include <rz_vector.h>
#include <rz_util/rz_print.h>
#include <rz_analysis.h>
#include <rz_analysis_optype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down

0 comments on commit 4a9e550

Please sign in to comment.