Skip to content

Commit

Permalink
Fix warnings when building with CAPSTONE_DIET (#2249)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Jan 20, 2024
1 parent c8c8009 commit 69d2241
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 15 deletions.
8 changes: 6 additions & 2 deletions arch/AArch64/AArch64GenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21264,8 +21264,10 @@ getRegisterName(unsigned RegNo, unsigned AltIdx) {
#ifdef PRINT_ALIAS_INSTR
#undef PRINT_ALIAS_INSTR

#ifndef CAPSTONE_DIET
static bool AArch64InstPrinterValidateMCOperand(const MCOperand *MCOp,
unsigned PredicateIndex);
#endif
static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) {
#ifndef CAPSTONE_DIET
static const PatternsForOpcode OpToPatterns[] = {
Expand Down Expand Up @@ -33325,11 +33327,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) {
#endif // CAPSTONE_DIET
}

#ifndef CAPSTONE_DIET
static void printCustomAliasOperand(
MCInst *MI, uint64_t Address, unsigned OpIdx,
unsigned PrintMethodIdx,
SStream *OS) {
#ifndef CAPSTONE_DIET
switch (PrintMethodIdx) {
default:
assert(0 && "Unknown PrintMethod kind");
Expand Down Expand Up @@ -33524,9 +33526,10 @@ static void printCustomAliasOperand(
printSysCROperand(MI, OpIdx, OS);
break;
}
#endif // CAPSTONE_DIET
}
#endif // CAPSTONE_DIET

#ifndef CAPSTONE_DIET
static bool AArch64InstPrinterValidateMCOperand(const MCOperand *MCOp,
unsigned PredicateIndex) {
switch (PredicateIndex) {
Expand Down Expand Up @@ -33610,5 +33613,6 @@ static bool AArch64InstPrinterValidateMCOperand(const MCOperand *MCOp,
}
}
}
#endif

#endif // PRINT_ALIAS_INSTR
2 changes: 2 additions & 0 deletions arch/AArch64/AArch64InstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@

#define DEBUG_TYPE "asm-printer"

#ifndef CAPSTONE_DIET
static void printCustomAliasOperand(
MCInst *MI, uint64_t Address, unsigned OpIdx,
unsigned PrintMethodIdx,
SStream *OS);
#endif

#define DECLARE_printComplexRotationOp(Angle, Remainder) \
static void CONCAT(printComplexRotationOp, CONCAT(Angle, Remainder))( \
Expand Down
4 changes: 2 additions & 2 deletions arch/ARM/ARMGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13336,10 +13336,10 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS)
#endif // CAPSTONE_DIET
}

#ifndef CAPSTONE_DIET
void printCustomAliasOperand(MCInst *MI, uint64_t Address, unsigned OpIdx,
unsigned PrintMethodIdx, SStream *OS)
{
#ifndef CAPSTONE_DIET
switch (PrintMethodIdx) {
default:
assert(0 && "Unknown PrintMethod kind");
Expand All @@ -13354,7 +13354,7 @@ void printCustomAliasOperand(MCInst *MI, uint64_t Address, unsigned OpIdx,
printMandatoryInvertedPredicateOperand(MI, OpIdx, OS);
break;
}
#endif // CAPSTONE_DIET
}
#endif // CAPSTONE_DIET

#endif // PRINT_ALIAS_INSTR
2 changes: 2 additions & 0 deletions arch/ARM/ARMInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@

// Static function declarations. These are functions which have the same identifiers
// over all architectures. Therefor they need to be static.
#ifndef CAPSTONE_DIET
static void printCustomAliasOperand(MCInst *MI, uint64_t Address,
unsigned OpIdx, unsigned PrintMethodIdx,
SStream *O);
#endif
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
static void printPredicateOperand(MCInst *MI, unsigned OpNum, SStream *O);
static void printRegName(SStream *OS, unsigned RegNo);
Expand Down
2 changes: 0 additions & 2 deletions arch/Alpha/AlphaGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1501,9 +1501,7 @@ static const char *getRegisterName(unsigned RegNo) {
#undef PRINT_ALIAS_INSTR

static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) {
#ifndef CAPSTONE_DIET
return false;
#endif // CAPSTONE_DIET
}

#endif // PRINT_ALIAS_INSTR
12 changes: 8 additions & 4 deletions arch/BPF/BPFMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ static bpf_insn op2insn_jmp(unsigned opcode)
return BPF_INS_INVALID;
}

#ifndef CAPSTONE_DIET
static void update_regs_access(cs_struct *ud, cs_detail *detail,
bpf_insn insn_id, unsigned int opcode)
{
Expand Down Expand Up @@ -357,6 +358,7 @@ static void update_regs_access(cs_struct *ud, cs_detail *detail,
break;
}
}
#endif

/*
* 1. Convert opcode(id) to BPF_INS_*
Expand All @@ -366,20 +368,20 @@ void BPF_get_insn_id(cs_struct *ud, cs_insn *insn, unsigned int opcode)
{
// No need to care the mode (cBPF or eBPF) since all checks has be done in
// BPF_getInstruction, we can simply map opcode to BPF_INS_*.
cs_detail *detail;
bpf_insn id = BPF_INS_INVALID;
#ifndef CAPSTONE_DIET
cs_detail *detail;
bpf_insn_group grp;

detail = insn->detail;
#ifndef CAPSTONE_DIET
#define PUSH_GROUP(grp) do { \
if (detail) { \
detail->groups[detail->groups_count] = grp; \
detail->groups_count++; \
} \
} while(0)
#else
#define PUSH_GROUP
#define PUSH_GROUP(grp) do {} while(0)
#endif

switch (BPF_CLASS(opcode)) {
Expand All @@ -400,13 +402,15 @@ void BPF_get_insn_id(cs_struct *ud, cs_insn *insn, unsigned int opcode)
PUSH_GROUP(BPF_GRP_ALU);
break;
case BPF_CLASS_JMP:
grp = BPF_GRP_JUMP;
id = op2insn_jmp(opcode);
#ifndef CAPSTONE_DIET
grp = BPF_GRP_JUMP;
if (id == BPF_INS_CALL || id == BPF_INS_CALLX)
grp = BPF_GRP_CALL;
else if (id == BPF_INS_EXIT)
grp = BPF_GRP_RETURN;
PUSH_GROUP(grp);
#endif
break;
case BPF_CLASS_RET:
id = BPF_INS_RET;
Expand Down
2 changes: 1 addition & 1 deletion arch/EVM/EVMMapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
static const cs_evm insns[256] = {
#include "EVMMappingInsn.inc"
};
#endif

// look for @id in @insns, given its size in @max.
// return -1 if not found
Expand All @@ -30,6 +29,7 @@ static int evm_insn_find(const cs_evm *insns, unsigned int max, unsigned int id)

return (int)id;
}
#endif

// fill in details
void EVM_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
Expand Down
2 changes: 1 addition & 1 deletion arch/MOS65XX/MOS65XXDisassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ static const struct OpInfo OpInfoTable[]= {

};

#ifndef CAPSTONE_DIET
static const char* const RegNames[] = {
"invalid", "A", "X", "Y", "P", "SP", "DP", "B", "K"
};

#ifndef CAPSTONE_DIET
static const char* const GroupNames[] = {
NULL,
"jump",
Expand Down
4 changes: 2 additions & 2 deletions arch/PowerPC/PPCGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15721,11 +15721,11 @@ static bool printAliasInstr(MCInst *MI, uint64_t Address, SStream *OS) {
#endif // CAPSTONE_DIET
}

#ifndef CAPSTONE_DIET
static void printCustomAliasOperand(
MCInst *MI, uint64_t Address, unsigned OpIdx,
unsigned PrintMethodIdx,
SStream *OS) {
#ifndef CAPSTONE_DIET
switch (PrintMethodIdx) {
default:
assert(0 && "Unknown PrintMethod kind");
Expand Down Expand Up @@ -15755,7 +15755,7 @@ static void printCustomAliasOperand(
printU5ImmOperand(MI, OpIdx, OS);
break;
}
#endif // CAPSTONE_DIET
}
#endif // CAPSTONE_DIET

#endif // PRINT_ALIAS_INSTR
2 changes: 2 additions & 0 deletions arch/PowerPC/PPCInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@

// Static function declarations. These are functions which have the same identifiers
// over all architectures. Therefor they need to be static.
#ifndef CAPSTONE_DIET
static void printCustomAliasOperand(MCInst *MI, uint64_t Address,
unsigned OpIdx, unsigned PrintMethodIdx,
SStream *O);
#endif
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
static void printPredicateOperand(MCInst *MI, unsigned OpNo, SStream *O,
const char *Modifier);
Expand Down
2 changes: 2 additions & 0 deletions arch/TMS320C64x/TMS320C64xGenAsmWriter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI) {
0U
};

#ifndef CAPSTONE_DIET
static const char AsmStrs[] = {
/* 0 */ 'n', 'o', 'p', 9, 9, 0,
/* 6 */ 's', 'u', 'b', '2', 9, 0,
Expand Down Expand Up @@ -428,6 +429,7 @@ static void printInstruction(MCInst *MI, SStream *O, MCRegisterInfo *MRI) {
/* 897 */ 'b', 9, 'n', 'r', 'p', 0,
/* 903 */ 'l', 'i', 'f', 'e', 't', 'i', 'm', 'e', '_', 's', 't', 'a', 'r', 't', 0,
};
#endif

// Emit the opcode for the instruction.
uint32_t Bits = OpInfo[MCInst_getOpcode(MI)];
Expand Down
4 changes: 3 additions & 1 deletion arch/X86/X86Mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,6 @@ static bool valid_bnd(cs_struct *h, unsigned int opcode)
// not found
return false;
}
#endif

// return true if the opcode is XCHG [mem]
static bool xchg_mem(unsigned int opcode)
Expand All @@ -1727,6 +1726,7 @@ static bool xchg_mem(unsigned int opcode)
return true;
}
}
#endif

// given MCInst's id, find out if this insn is valid for REP prefix
static bool valid_rep(cs_struct *h, unsigned int opcode)
Expand Down Expand Up @@ -1783,6 +1783,7 @@ static bool valid_rep(cs_struct *h, unsigned int opcode)
return false;
}

#ifndef CAPSTONE_DIET
// given MCInst's id, find if this is a "repz ret" instruction
// gcc generates "repz ret" (f3 c3) instructions in some cases as an
// optimization for AMD platforms, see:
Expand All @@ -1800,6 +1801,7 @@ static bool valid_ret_repz(cs_struct *h, unsigned int opcode)
// not found
return false;
}
#endif

// given MCInst's id, find out if this insn is valid for REPE prefix
static bool valid_repe(cs_struct *h, unsigned int opcode)
Expand Down
2 changes: 2 additions & 0 deletions cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ cs_err CAPSTONE_API cs_close(csh *handle)
// replace str1 in target with str2; target starts with str1
// output is put into result (which is array of char with size CS_MNEMONIC_SIZE)
// return 0 on success, -1 on failure
#ifndef CAPSTONE_DIET
static int str_replace(char *result, char *target, const char *str1, char *str2)
{
// only perform replacement if the output fits into result
Expand All @@ -576,6 +577,7 @@ static int str_replace(char *result, char *target, const char *str1, char *str2)
} else
return -1;
}
#endif

/// The asm string sometimes has a leading space or tab.
/// Here we remove it.
Expand Down

0 comments on commit 69d2241

Please sign in to comment.