summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2013-03-10 21:56:51 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2013-03-10 21:56:51 (GMT)
commite7a85861ba8bcd00ceb7bf9e47f4eadccd48ce3f (patch)
tree057d22b37b8c0c94a2162be624cdc23d71f51242 /src
parente398035b1634ff55247a366e862c15965e7945bc (diff)
Extended and improved some parts of instructions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@344 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src')
-rw-r--r--src/arch/instruction-int.h3
-rw-r--r--src/arch/instruction.c58
-rw-r--r--src/arch/instruction.h3
3 files changed, 50 insertions, 14 deletions
diff --git a/src/arch/instruction-int.h b/src/arch/instruction-int.h
index d7da215..4a38eb5 100644
--- a/src/arch/instruction-int.h
+++ b/src/arch/instruction-int.h
@@ -64,9 +64,10 @@ struct _GArchInstruction
size_t operands_count; /* Nbre. d'opérandes utilisées */
GArchInstruction **from; /* Origines des références */
+ InstructionLinkType *from_types; /* Type des liens de dest. */
size_t from_count; /* Nombre de ces origines */
GArchInstruction **to; /* Eventuelles lignes visées */
- InstructionLinkType *links_type; /* Type des liens de dest. */
+ InstructionLinkType *to_types; /* Type des liens de dest. */
link_extra_info *links_info; /* Informations complémentaires*/
size_t to_count; /* Nombre de ces destinations */
diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index 20b5f3a..c40ff51 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -363,35 +363,41 @@ bool g_arch_instruction_is_return(const GArchInstruction *instr)
void g_arch_instruction_link_with(GArchInstruction *instr, GArchInstruction *dest, InstructionLinkType type, ...)
{
+ size_t count; /* Raccourci pour la lecture */
va_list ap; /* Gestion des variations */
/* Côté destination */
+ count = ++dest->from_count;
+
dest->from = (GArchInstruction **)realloc(dest->from,
- ++dest->from_count * sizeof(GArchInstruction *));
+ count * sizeof(GArchInstruction *));
+ dest->from_types = (InstructionLinkType *)realloc(dest->from_types,
+ count * sizeof(InstructionLinkType));
- dest->from[dest->from_count - 1] = instr;
+ dest->from[count - 1] = instr;
+ dest->from_types[count - 1] = type;
/* Côté point de départ */
- instr->to_count++;
+ count = ++instr->to_count;
instr->to = (GArchInstruction **)realloc(instr->to,
- instr->to_count * sizeof(GArchInstruction *));
- instr->links_type = (InstructionLinkType *)realloc(instr->links_type,
- instr->to_count * sizeof(InstructionLinkType));
+ count * sizeof(GArchInstruction *));
+ instr->to_types = (InstructionLinkType *)realloc(instr->to_types,
+ count * sizeof(InstructionLinkType));
instr->links_info = (link_extra_info *)realloc(instr->links_info,
- instr->to_count * sizeof(link_extra_info));
+ count * sizeof(link_extra_info));
- instr->to[instr->to_count - 1] = dest;
- instr->links_type[instr->to_count - 1] = type;
+ instr->to[count - 1] = dest;
+ instr->to_types[count - 1] = type;
va_start(ap, type);
switch (type)
{
case ILT_CASE_JUMP:
- instr->links_info[instr->to_count - 1].imm = va_arg(ap, GImmOperand *);
+ instr->links_info[count - 1].imm = va_arg(ap, GImmOperand *);
break;
default:
break;
@@ -424,6 +430,32 @@ bool g_arch_instruction_has_sources(const GArchInstruction *instr)
/******************************************************************************
* *
* Paramètres : instr = instruction dont les informations sont à consulter. *
+* dests = liste des instructions de destination. [OUT] *
+* types = liste des types de liens présents. [OUT] *
+* *
+* Description : Fournit les origines d'une instruction donnée. *
+* *
+* Retour : Nombre de ces destinations. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+size_t g_arch_instruction_get_sources(const GArchInstruction *instr, GArchInstruction ***dests, InstructionLinkType **types)
+{
+ *dests = instr->from;
+
+ if (types != NULL)
+ *types = instr->from_types;
+
+ return instr->from_count;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : instr = instruction dont les informations sont à consulter. *
* *
* Description : Indique si l'instruction a une suite autre que la suivante. *
* *
@@ -436,7 +468,7 @@ bool g_arch_instruction_has_sources(const GArchInstruction *instr)
bool g_arch_instruction_has_destinations(const GArchInstruction *instr)
{
/* FIXME !? */
- //return (instr->to_count > 1 || (instr->to_count == 1 && instr->links_type[0] != ILT_CALL));
+ //return (instr->to_count > 1 || (instr->to_count == 1 && instr->to_types[0] != ILT_CALL));
return (instr->to_count > 0);
}
@@ -462,7 +494,7 @@ size_t g_arch_instruction_get_destinations(const GArchInstruction *instr, GArchI
*dests = instr->to;
if (types != NULL)
- *types = instr->links_type;
+ *types = instr->to_types;
if (info != NULL)
*info = instr->links_info;
@@ -493,7 +525,7 @@ GArchInstruction *g_arch_instruction_get_given_destination(const GArchInstructio
result = NULL;
for (i = 0; i < instr->to_count && result == NULL; i++)
- if (instr->links_type[i] == type)
+ if (instr->to_types[i] == type)
result = instr->to[i];
return result;
diff --git a/src/arch/instruction.h b/src/arch/instruction.h
index 59577dc..c4b704e 100644
--- a/src/arch/instruction.h
+++ b/src/arch/instruction.h
@@ -118,6 +118,9 @@ void g_arch_instruction_link_with(GArchInstruction *, GArchInstruction *, Instru
/* Indique si l'instruction a une ou plusieurs origines. */
bool g_arch_instruction_has_sources(const GArchInstruction *);
+/* Fournit les origines d'une instruction donnée. */
+size_t g_arch_instruction_get_sources(const GArchInstruction *, GArchInstruction ***, InstructionLinkType **);
+
/* Indique si l'instruction a une suite autre que la suivante. */
bool g_arch_instruction_has_destinations(const GArchInstruction *);