Skip to content

Commit

Permalink
arm: use CreateImm0() & CreateReg0() to create MCOperand* to avoid us…
Browse files Browse the repository at this point in the history
…ing malloc/free to improve performance
  • Loading branch information
aquynh committed Jun 9, 2014
1 parent 8c1104b commit 0f648ea
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 159 deletions.
9 changes: 3 additions & 6 deletions MCInst.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void MCInst_insert(MCInst *inst, int index, MCOperand *Op)
cs_mem_free(Op);
}

// do not free @Op
void MCInst_insert0(MCInst *inst, int index, MCOperand *Op)
{
int i;
Expand Down Expand Up @@ -173,8 +174,7 @@ MCOperand *MCOperand_CreateReg(unsigned Reg)
return op;
}

/*
MCOperand *MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)
MCOperand *MCOperand_CreateReg1(MCInst *mcInst, unsigned Reg)
{
MCOperand *op = &(mcInst->Operands[MCINST_CACHE]);

Expand All @@ -183,7 +183,6 @@ MCOperand *MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)

return op;
}
*/

void MCOperand_CreateReg0(MCInst *mcInst, unsigned Reg)
{
Expand All @@ -204,8 +203,7 @@ MCOperand *MCOperand_CreateImm(int64_t Val)
return op;
}

/*
MCOperand *MCOperand_CreateImm0(MCInst *mcInst, int64_t Val)
MCOperand *MCOperand_CreateImm1(MCInst *mcInst, int64_t Val)
{
MCOperand *op = &(mcInst->Operands[MCINST_CACHE]);

Expand All @@ -214,7 +212,6 @@ MCOperand *MCOperand_CreateImm0(MCInst *mcInst, int64_t Val)

return op;
}
*/

void MCOperand_CreateImm0(MCInst *mcInst, int64_t Val)
{
Expand Down
12 changes: 12 additions & 0 deletions MCInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@ MCOperand *MCOperand_CreateImm(int64_t Val);

MCOperand *MCOperand_CreateFPImm(double Val);

// create Reg operand in the next slot
void MCOperand_CreateReg0(MCInst *inst, unsigned Reg);

// create Reg operand use the last-unused slot
MCOperand *MCOperand_CreateReg1(MCInst *inst, unsigned Reg);

// create Imm operand in the next slot
void MCOperand_CreateImm0(MCInst *inst, int64_t Val);

// create Imm operand in the last-unused slot
MCOperand *MCOperand_CreateImm1(MCInst *inst, int64_t Val);

/// MCInst - Instances of this class represent a single low-level machine
/// instruction.
struct MCInst {
Expand All @@ -107,8 +115,12 @@ void MCInst_Init(cs_struct *handle, MCInst *inst);

void MCInst_clear(MCInst *inst);

// free operand after inserting
void MCInst_insert(MCInst *inst, int index, MCOperand *Op);

// do not free operand after inserting
void MCInst_insert0(MCInst *inst, int index, MCOperand *Op);

void MCInst_setOpcode(MCInst *inst, unsigned Op);

unsigned MCInst_getOpcode(const MCInst*);
Expand Down
Loading

0 comments on commit 0f648ea

Please sign in to comment.