Skip to content

Commit

Permalink
Replace asserts & add Expr handling
Browse files Browse the repository at this point in the history
  • Loading branch information
R33v0LT committed Dec 17, 2024
1 parent 165c01b commit d98e2be
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion arch/ARC/ARCGenCSInsnEnum.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/* https://github.com/capstone-engine/llvm-capstone */

ARC_INS_INVALID,
ARC_INS_#,
ARC_INS_HASH,
ARC_INS_PBR,
ARC_INS_ERROR_FLS,
ARC_INS_ERROR_FFS,
Expand Down
2 changes: 1 addition & 1 deletion arch/ARC/ARCGenCSMappingInsnName.inc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/* https://github.com/capstone-engine/llvm-capstone */

"invalid", // ARC_INS_INVALID
"#", // ARC_INS_#
"#", // ARC_INS_HASH
"pbr", // ARC_INS_PBR
"error_fls", // ARC_INS_ERROR_FLS
"error_ffs", // ARC_INS_ERROR_FFS
Expand Down
18 changes: 9 additions & 9 deletions arch/ARC/ARCGenCSMappingInsnOp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -824,13 +824,13 @@
{{{ /* ARC_G_UBFX (270) - ARC_INS_INVALID - */
0
}}},
{ /* ARC_ADJCALLSTACKDOWN (271) - ARC_INS_# - # ADJCALLSTACKDOWN $amt, $amt2 */
{ /* ARC_ADJCALLSTACKDOWN (271) - ARC_INS_HASH - # ADJCALLSTACKDOWN $amt, $amt2 */
{
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* amt */
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* amt2 */
{ 0 }
}},
{ /* ARC_ADJCALLSTACKUP (272) - ARC_INS_# - # ADJCALLSTACKUP $amt1 */
{ /* ARC_ADJCALLSTACKUP (272) - ARC_INS_HASH - # ADJCALLSTACKUP $amt1 */
{
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* amt1 */
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* amt2 */
Expand Down Expand Up @@ -2898,7 +2898,7 @@
}},
{ /* ARC_POP_S_r (584) - ARC_INS_POP_S - pop_s $b3 */
{
{ CS_OP_INVALID, CS_AC_WRITE, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_REG, CS_AC_WRITE, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ 0 }
}},
{ /* ARC_PUSH_S_BLINK (585) - ARC_INS_PUSH_S - push_s %blink */
Expand All @@ -2907,7 +2907,7 @@
}},
{ /* ARC_PUSH_S_r (586) - ARC_INS_PUSH_S - push_s $b3 */
{
{ CS_OP_INVALID, CS_AC_READ, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_REG, CS_AC_READ, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ 0 }
}},
{ /* ARC_ROR_cc_f_rru6 (587) - ARC_INS_ROR_ - ror.${cc}.f $A, $B, $U6 */
Expand Down Expand Up @@ -3224,7 +3224,7 @@
}},
{ /* ARC_SP_ADD_S (631) - ARC_INS_ADD_S - add_s $b3, %sp, $u7 */
{
{ CS_OP_INVALID, CS_AC_WRITE, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_REG, CS_AC_WRITE, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* u7 */
{ 0 }
}},
Expand All @@ -3235,25 +3235,25 @@
}},
{ /* ARC_SP_LDB_S (633) - ARC_INS_LDB_S - ldb_s $b3, [%sp, $u7] */
{
{ CS_OP_INVALID, CS_AC_WRITE, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_REG, CS_AC_WRITE, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* u7 */
{ 0 }
}},
{ /* ARC_SP_LD_S (634) - ARC_INS_LD_S - ld_s $b3, [%sp, $u7] */
{
{ CS_OP_INVALID, CS_AC_WRITE, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_REG, CS_AC_WRITE, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* u7 */
{ 0 }
}},
{ /* ARC_SP_STB_S (635) - ARC_INS_STB_S - stb_s $b3, [%sp, $u7] */
{
{ CS_OP_INVALID, CS_AC_READ, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_REG, CS_AC_READ, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* u7 */
{ 0 }
}},
{ /* ARC_SP_ST_S (636) - ARC_INS_ST_S - st_s $b3, [%sp, $u7] */
{
{ CS_OP_INVALID, CS_AC_READ, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_REG, CS_AC_READ, { CS_DATA_TYPE_iAny, CS_DATA_TYPE_LAST } }, /* b3 */
{ CS_OP_IMM, CS_AC_READ, { CS_DATA_TYPE_i32, CS_DATA_TYPE_LAST } }, /* u7 */
{ 0 }
}},
Expand Down
8 changes: 3 additions & 5 deletions arch/ARC/ARCInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,10 @@ static void printOperand(MCInst *MI, unsigned OpNum, SStream *O)
MCOperand *Op = MCInst_getOperand(MI, (OpNum));
if (MCOperand_isReg(Op)) {
printRegName(O, MCOperand_getReg(Op));
return;
}

if (MCOperand_isImm(Op) || MCOperand_isExpr(Op)) {
} else if (MCOperand_isImm(Op)) {
SStream_concat(O, "%" PRId64, MCOperand_getImm(Op));
return;
} else if (MCOperand_isExpr(Op)) {
printExpr(O, MCOperand_getExpr(Op));
}
}

Expand Down
20 changes: 11 additions & 9 deletions arch/ARC/ARCMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ void ARC_add_cs_detail(MCInst *MI, int op_group,
cs_op_type op_type = map_get_op_type(MI, OpNum);
cs_op_type base_op_type = op_type;
cs_op_type offset_op_type;
printf("op_group: %d\n", op_group);
// Fill cs_detail
switch (op_group) {
default:
Expand All @@ -236,49 +235,52 @@ void ARC_add_cs_detail(MCInst *MI, int op_group,
} else if (op_type == CS_OP_REG) {
ARC_set_detail_op_reg(MI, OpNum,
MCInst_getOpVal(MI, OpNum));
} else
assert(0 && "Op type not handled.");
} else {
// Expression
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
MCOperand_getImm(MCInst_getOperand(MI, OpNum)));
}
break;
case ARC_OP_GROUP_PredicateOperand:
if (op_type == CS_OP_IMM) {
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
MCInst_getOpVal(MI, OpNum));
} else
assert(0 && "Op type not handled.");
CS_ASSERT(0 && "Op type not handled.");
break;
case ARC_OP_GROUP_MemOperandRI:
if (base_op_type == CS_OP_REG) {
ARC_set_detail_op_reg(MI, OpNum,
MCInst_getOpVal(MI, OpNum));
} else
assert(0 && "Op type not handled.");
CS_ASSERT(0 && "Op type not handled.");
offset_op_type = map_get_op_type(MI, OpNum+1);
if (offset_op_type == CS_OP_IMM) {
ARC_set_detail_op_imm(MI, OpNum+1, ARC_OP_IMM,
MCInst_getOpVal(MI, OpNum+1));
} else
assert(0 && "Op type not handled.");
CS_ASSERT(0 && "Op type not handled.");
break;
case ARC_OP_GROUP_BRCCPredicateOperand:
if (op_type == CS_OP_IMM) {
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
MCInst_getOpVal(MI, OpNum));
} else
assert(0 && "Op type not handled.");
CS_ASSERT(0 && "Op type not handled.");
break;
case ARC_OP_GROUP_CCOperand:
if (op_type == CS_OP_IMM) {
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
MCInst_getOpVal(MI, OpNum));
} else
assert(0 && "Op type not handled.");
CS_ASSERT(0 && "Op type not handled.");
break;
case ARC_OP_GROUP_U6:
if (op_type == CS_OP_IMM) {
ARC_set_detail_op_imm(MI, OpNum, ARC_OP_IMM,
MCInst_getOpVal(MI, OpNum));
} else
assert(0 && "Op type not handled.");
CS_ASSERT(0 && "Op type not handled.");
break;
}
}
Expand Down

0 comments on commit d98e2be

Please sign in to comment.