From d1d91e68e9665db1808f31dc2310ba58ee5631fa Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Fri, 3 Aug 2018 13:56:10 +0200
Subject: Provided all instruction links at once.

---
 src/arch/instruction.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/arch/instruction.h |  6 ++++
 2 files changed, 97 insertions(+)

diff --git a/src/arch/instruction.c b/src/arch/instruction.c
index 55aee49..1bf3c9b 100644
--- a/src/arch/instruction.c
+++ b/src/arch/instruction.c
@@ -25,6 +25,7 @@
 
 
 #include <assert.h>
+#include <malloc.h>
 #include <stdarg.h>
 #include <string.h>
 
@@ -947,6 +948,51 @@ const instr_link_t *g_arch_instruction_get_source(GArchInstruction *instr, size_
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : instr = instruction dont les informations sont à consulter.  *
+*                count = quantié de liens présents. [OUT]                     *
+*                                                                             *
+*  Description : Fournit tous les détails d'origine d'une instruction donnée. *
+*                                                                             *
+*  Retour      : Liens vers des instructions d'origine à libérer.             *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+instr_link_t *g_arch_instruction_get_sources(GArchInstruction *instr, size_t *count)
+{
+    instr_link_t *result;                   /* Détails présents à renvoyer */
+    size_t i;                               /* Boucle de parcours          */
+    const instr_link_t *link;               /* Lien à fournir              */
+
+    g_arch_instruction_lock_src(instr);
+
+    *count = g_arch_instruction_count_sources(instr);
+
+    if (*count == 0)
+        result = NULL;
+
+    else
+    {
+        result = (instr_link_t *)malloc(*count * sizeof(instr_link_t));
+
+        for (i = 0; i < *count; i++)
+        {
+            link = g_arch_instruction_get_source(instr, i);
+            memcpy(&result[i], link, sizeof(instr_link_t));
+        }
+
+    }
+
+    g_arch_instruction_unlock_src(instr);
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : instr = instruction dont les informations sont à consulter.  *
 *                                                                             *
 *  Description : Donne le nombre d'instructions non naturellement suivantes.  *
 *                                                                             *
@@ -1040,6 +1086,51 @@ GArchInstruction *g_arch_instruction_get_given_destination(GArchInstruction *ins
 }
 
 
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : instr = instruction dont les informations sont à consulter.  *
+*                count = quantié de liens présents. [OUT]                     *
+*                                                                             *
+*  Description : Fournit tous les détails de destination d'une instruction.   *
+*                                                                             *
+*  Retour      : Liens vers des instructions de destination à libérer.        *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+instr_link_t *g_arch_instruction_get_destinations(GArchInstruction *instr, size_t *count)
+{
+    instr_link_t *result;                   /* Détails présents à renvoyer */
+    size_t i;                               /* Boucle de parcours          */
+    const instr_link_t *link;               /* Lien à fournir              */
+
+    g_arch_instruction_lock_dest(instr);
+
+    *count = g_arch_instruction_count_destinations(instr);
+
+    if (*count == 0)
+        result = NULL;
+
+    else
+    {
+        result = (instr_link_t *)malloc(*count * sizeof(instr_link_t));
+
+        for (i = 0; i < *count; i++)
+        {
+            link = g_arch_instruction_get_destination(instr, i);
+            memcpy(&result[i], link, sizeof(instr_link_t));
+        }
+
+    }
+
+    g_arch_instruction_unlock_dest(instr);
+
+    return result;
+
+}
+
+
 
 /* ---------------------------------------------------------------------------------- */
 /*                       CONVERSIONS DU FORMAT DES INSTRUCTIONS                       */
diff --git a/src/arch/instruction.h b/src/arch/instruction.h
index 34dc59f..0c8510a 100644
--- a/src/arch/instruction.h
+++ b/src/arch/instruction.h
@@ -236,6 +236,9 @@ size_t g_arch_instruction_count_sources(const GArchInstruction *);
 /* Fournit les détails d'une origine d'une instruction donnée. */
 const instr_link_t *g_arch_instruction_get_source(GArchInstruction *, size_t);
 
+/* Fournit tous les détails d'origine d'une instruction donnée. */
+instr_link_t *g_arch_instruction_get_sources(GArchInstruction *, size_t *);
+
 #define g_arch_instruction_lock_dest(ins) g_arch_instruction_lock_unlock_links(ins, false, true)
 #define g_arch_instruction_unlock_dest(ins) g_arch_instruction_lock_unlock_links(ins, false, false)
 
@@ -248,6 +251,9 @@ const instr_link_t *g_arch_instruction_get_destination(GArchInstruction *, size_
 /* Fournit la destination d'une instruction et d'un type donné. */
 GArchInstruction *g_arch_instruction_get_given_destination(GArchInstruction *, InstructionLinkType);
 
+/* Fournit tous les détails de destination d'une instruction. */
+instr_link_t *g_arch_instruction_get_destinations(GArchInstruction *, size_t *);
+
 
 
 /* --------------------- CONVERSIONS DU FORMAT DES INSTRUCTIONS --------------------- */
-- 
cgit v0.11.2-87-g4458