diff options
Diffstat (limited to 'src/arch/instruction.c')
-rw-r--r-- | src/arch/instruction.c | 147 |
1 files changed, 103 insertions, 44 deletions
diff --git a/src/arch/instruction.c b/src/arch/instruction.c index 7df72bf..339364f 100644 --- a/src/arch/instruction.c +++ b/src/arch/instruction.c @@ -145,6 +145,8 @@ static void g_arch_instruction_class_init(GArchInstructionClass *klass) static void g_arch_instruction_init(GArchInstruction *instr) { + instr->operands_lock = 0; + instr->from_count = 0; instr->to_count = 0; @@ -409,6 +411,91 @@ void g_arch_instruction_get_location(const GArchInstruction *instr, off_t *offse } + +/****************************************************************************** +* * +* Paramètres : instr = instruction à consulter. * +* rregs = liste des rgistres lus. [OUT] * +* rcount = nombre de registres lus. [OUT] * +* wregs = liste des rgistres écrits. [OUT] * +* wcount = nombre de registres écrits. [OUT] * +* * +* Description : Liste les registres lus et écrits par l'instruction. * +* * +* Retour : - * +* * +* Remarques : Les compteurs de références sont à décrémenter après usage ! * +* * +******************************************************************************/ + +void g_arch_instruction_get_rw_registers(const GArchInstruction *instr, GArchRegister ***rregs, size_t *rcount, GArchRegister ***wregs, size_t *wcount) +{ +#if 0 + + size_t i; /* Boucle de parcours */ + + *rregs = NULL; + *rcount = 0; + *wregs = NULL; + *wcount = 0; + + instr->get_rw_regs(instr, rregs, rcount, wregs, wcount); + + for (i = 0; i < *rcount; i++) + g_object_ref(G_OBJECT((*rregs)[i])); + + for (i = 0; i < *wcount; i++) + g_object_ref(G_OBJECT((*wregs)[i])); + +#endif + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* MANIPULATION DES OPERANDES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : instr = instruction à mettre à jour. * +* * +* Description : Verrouille les accès la liste des opérandes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_arch_instruction_lock_operands(GArchInstruction *instr) +{ + g_bit_lock(&instr->operands_lock, 0); + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction à mettre à jour. * +* * +* Description : Déverrouille les accès la liste des opérandes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_arch_instruction_unlock_operands(GArchInstruction *instr) +{ + g_bit_unlock(&instr->operands_lock, 0); + +} + + /****************************************************************************** * * * Paramètres : instr = instance à mettre à jour. * @@ -424,11 +511,15 @@ void g_arch_instruction_get_location(const GArchInstruction *instr, off_t *offse void g_arch_instruction_attach_extra_operand(GArchInstruction *instr, GArchOperand *operand) { + g_arch_instruction_lock_operands(instr); + instr->operands_count++; instr->operands = (GArchOperand **)realloc(instr->operands, instr->operands_count * sizeof(GArchOperand *)); instr->operands[instr->operands_count - 1] = operand; + g_arch_instruction_unlock_operands(instr); + } @@ -444,8 +535,10 @@ void g_arch_instruction_attach_extra_operand(GArchInstruction *instr, GArchOpera * * ******************************************************************************/ -size_t g_arch_instruction_count_operands(const GArchInstruction *instr) +size_t _g_arch_instruction_count_operands(const GArchInstruction *instr) { + assert(instr->operands_lock != 0); + return instr->operands_count; } @@ -464,10 +557,12 @@ size_t g_arch_instruction_count_operands(const GArchInstruction *instr) * * ******************************************************************************/ -GArchOperand *g_arch_instruction_get_operand(const GArchInstruction *instr, size_t index) +GArchOperand *_g_arch_instruction_get_operand(const GArchInstruction *instr, size_t index) { GArchOperand *result; /* Opérande à retourner */ + assert(instr->operands_lock != 0); + if (index >= instr->operands_count) result = NULL; else result = instr->operands[index]; @@ -492,10 +587,12 @@ GArchOperand *g_arch_instruction_get_operand(const GArchInstruction *instr, size * * ******************************************************************************/ -void g_arch_instruction_replace_operand(GArchInstruction *instr, GArchOperand *new, const GArchOperand *old) +void _g_arch_instruction_replace_operand(GArchInstruction *instr, GArchOperand *new, const GArchOperand *old) { size_t i; /* Boucle de parcours */ + assert(instr->operands_lock != 0); + for (i = 0; i < instr->operands_count; i++) if (instr->operands[i] == old) break; @@ -522,10 +619,12 @@ void g_arch_instruction_replace_operand(GArchInstruction *instr, GArchOperand *n * * ******************************************************************************/ -void g_arch_instruction_detach_operand(GArchInstruction *instr, GArchOperand *operand) +void _g_arch_instruction_detach_operand(GArchInstruction *instr, GArchOperand *operand) { size_t i; /* Boucle de parcours */ + assert(instr->operands_lock != 0); + for (i = 0; i < instr->operands_count; i++) if (instr->operands[i] == operand) break; @@ -540,46 +639,6 @@ void g_arch_instruction_detach_operand(GArchInstruction *instr, GArchOperand *op } -/****************************************************************************** -* * -* Paramètres : instr = instruction à consulter. * -* rregs = liste des rgistres lus. [OUT] * -* rcount = nombre de registres lus. [OUT] * -* wregs = liste des rgistres écrits. [OUT] * -* wcount = nombre de registres écrits. [OUT] * -* * -* Description : Liste les registres lus et écrits par l'instruction. * -* * -* Retour : - * -* * -* Remarques : Les compteurs de références sont à décrémenter après usage ! * -* * -******************************************************************************/ - -void g_arch_instruction_get_rw_registers(const GArchInstruction *instr, GArchRegister ***rregs, size_t *rcount, GArchRegister ***wregs, size_t *wcount) -{ -#if 0 - - size_t i; /* Boucle de parcours */ - - *rregs = NULL; - *rcount = 0; - *wregs = NULL; - *wcount = 0; - - instr->get_rw_regs(instr, rregs, rcount, wregs, wcount); - - for (i = 0; i < *rcount; i++) - g_object_ref(G_OBJECT((*rregs)[i])); - - for (i = 0; i < *wcount; i++) - g_object_ref(G_OBJECT((*wregs)[i])); - -#endif - -} - - /* ---------------------------------------------------------------------------------- */ /* DEFINITION DES LIAISONS ENTRE INSTRUCTIONS */ |