summaryrefslogtreecommitdiff
path: root/src/gtkext/graph/nodes/flow.c
blob: 6bb2617b250ec1f0af6743ce80358d9bddc06687 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840

/* OpenIDA - Outil d'analyse de fichiers binaires
 * flow.c - encapsulation graphique des blocs d'exécution
 *
 * Copyright (C) 2013 Cyrille Bagard
 *
 *  This file is part of OpenIDA.
 *
 *  OpenIDA is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpenIDA is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "flow.h"


#include "../layout.h"
#include "../node-int.h"



/* Type d'un accrochage pour lien */
struct _node_slot_t
{
    GArchInstruction *instr;                /* Instruction liée            */
    size_t group_index;                     /* Rang dans le grp d'origine  */

    InstructionLinkType type;               /* Type de lien à représenter  */
    size_t slot_index;                      /* Position dans l'accroche    */
    gint x;                                 /* Abscisse graphique du rendu */

};

/* Encapsulation graphique d'un bloc d'exécution (instance) */
struct _GFlowNode
{
    GGraphNode parent;                      /* A laisser en premier        */

    GFlowBlock *block;                      /* Bloc d'exécution associé    */
    GtkBufferView *view;                    /* Représentation graphique    */

    node_slot_t *entries;                   /* Positions des pts d'entrées */
    size_t entries_count;                   /* Nombre de ces points        */
    node_slot_t *exits;                     /* Positions des pts de sorties*/
    size_t exits_count;                     /* Nombre de ces points        */

};

/* Encapsulation graphique d'un bloc d'exécution (classe) */
struct _GFlowNodeClass
{
    GGraphNodeClass parent;                 /* A laisser en premier        */

};


#define SPACE_BETWEEN_SLOT 15


/* Initialise la classe des encapsulations de bloc d'exécution. */
static void g_flow_node_class_init(GFlowNodeClass *);

/* Initialise une encapsulation de bloc d'exécution. */
static void g_flow_node_init(GFlowNode *);

/* Supprime toutes les références externes. */
static void g_flow_node_dispose(GFlowNode *);

/* Procède à la libération totale de la mémoire. */
static void g_flow_node_finalize(GFlowNode *);

/* Fournit le rang du noeud dans le graphique. */
static unsigned int g_flow_node_get_rank(const GFlowNode *);

/* Organise le contenu du noeud selon l'axe des abscisses. */
static void g_flow_node_prepare_x_line(GFlowNode *, GGraphNode *);

/* Parcourt tous les blocs d'instructions dans un ordre donné. */
static bool g_flow_node_visit_flow_nodes(GFlowNode *, graph_node_visitor_cb, void *);



/* ------------------------ GESTION DES ACCROCHES D'UN NOEUD ------------------------ */


/* Prépare les points d'entrées du noeud. */
static void g_flow_node_setup_entry_slots(GFlowNode *);

/* Prépare les points de sorties du noeud. */
static void g_flow_node_setup_exit_slots(GFlowNode *);

/* Etablit un lien entre deux noeuds graphiques. */
static node_slot_t *g_flow_node_get_slot(const GFlowNode *, bool, GArchInstruction *, size_t);

/* Localise un point d'accroche à un noeud graphique. */
static gint g_flow_node_get_slot_offset(const GFlowNode *, bool, const node_slot_t *);




/* Indique le type définit par la GLib pour l'encapsulation d'un bloc d'exécution. */
G_DEFINE_TYPE(GFlowNode, g_flow_node, G_TYPE_GRAPH_NODE);


/******************************************************************************
*                                                                             *
*  Paramètres  : klass = classe à initialiser.                                *
*                                                                             *
*  Description : Initialise la classe des encapsulations de bloc d'exécution. *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_flow_node_class_init(GFlowNodeClass *klass)
{
    GObjectClass *object;                   /* Autre version de la classe  */

    object = G_OBJECT_CLASS(klass);

    object->dispose = (GObjectFinalizeFunc/* ! */)g_flow_node_dispose;
    object->finalize = (GObjectFinalizeFunc)g_flow_node_finalize;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node = instance à initialiser.                               *
*                                                                             *
*  Description : Initialise une encapsulation de bloc d'exécution.            *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_flow_node_init(GFlowNode *node)
{
    GGraphNode *base;                       /* Version basique             */

    base = G_GRAPH_NODE(node);

    base->get_rank = (get_node_rank_fc)g_flow_node_get_rank;
    base->prepare_x = (node_prepare_x_fc)g_flow_node_prepare_x_line;
    base->visit = (visit_flow_nodes_fc)g_flow_node_visit_flow_nodes;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node = instance d'objet GLib à traiter.                      *
*                                                                             *
*  Description : Supprime toutes les références externes.                     *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_flow_node_dispose(GFlowNode *node)
{
    size_t i;                               /* Boucle de parcours          */

    g_object_unref(G_OBJECT(node->block));
    g_object_unref(G_OBJECT(node->view));

    for (i = 0; i < node->entries_count; i++)
        g_object_unref(G_OBJECT(node->entries[i].instr));

    for (i = 0; i < node->exits_count; i++)
        g_object_unref(G_OBJECT(node->exits[i].instr));

    G_OBJECT_CLASS(g_flow_node_parent_class)->dispose(G_OBJECT(node));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node = instance d'objet GLib à traiter.                      *
*                                                                             *
*  Description : Procède à la libération totale de la mémoire.                *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_flow_node_finalize(GFlowNode *node)
{
    if (node->entries != NULL)
        free(node->entries);

    if (node->exits != NULL)
        free(node->exits);

    G_OBJECT_CLASS(g_flow_node_parent_class)->finalize(G_OBJECT(node));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : block = bloc d'exécution représenté graphiquement.           *
*                view  = morceau d'affichage à représenter.                   *
*                                                                             *
*  Description : Encapsule graphiquement un bloc d'exécution.                 *
*                                                                             *
*  Retour      : Adresse de la structure mise en place.                       *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GGraphNode *g_flow_node_new(GFlowBlock *block, GtkBufferView *view)
{
    GFlowNode *result;                      /* Structure à retourner       */
    GtkRequisition requisition;             /* Taille à l'écran actuelle   */

    result = g_object_new(G_TYPE_FLOW_NODE, NULL);

    g_object_ref(G_OBJECT(block));
    g_object_ref(G_OBJECT(view));

    result->block = block;
    result->view = view;

    gtk_widget_size_request(GTK_WIDGET(result->view), &requisition);

    G_GRAPH_NODE(result)->alloc.width = requisition.width;
    G_GRAPH_NODE(result)->alloc.height = requisition.height;

    g_flow_node_setup_entry_slots(result);
    g_flow_node_setup_exit_slots(result);

    return G_GRAPH_NODE(result);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node = noeud graphique à consulter.                          *
*                                                                             *
*  Description : Fournit le rang du noeud dans le graphique.                  *
*                                                                             *
*  Retour      : Indice supérieur ou égal à zéro.                             *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static unsigned int g_flow_node_get_rank(const GFlowNode *node)
{
    return g_flow_block_get_rank(node->block);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node  = noeud d'encapsulation à traiter.                     *
*                nodes = ensemble des noeuds en place.                        *
*                                                                             *
*  Description : Organise le contenu du noeud selon l'axe des abscisses.      *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_flow_node_prepare_x_line(GFlowNode *node, GGraphNode *nodes)
{
    GGraphNode *base;                       /* Autre vision de l'instance  */
    GArchInstruction *last;                 /* Dernière instr. du noeud    */
    GFlowNode *target;                      /* Bloc visé par le lien       */
    node_slot_t *dest_slot;                 /* Accrochage d'arrivée        */
    pending_position pos;                   /* Position à transmettre      */
    GFlowNode *target_a;                    /* Bloc visé par le lien #a    */
    GFlowNode *target_b;                    /* Bloc visé par le lien #b    */
    unsigned int rank_a;                    /* Indice du rang associé #a   */
    unsigned int rank_b;                    /* Indice du rang associé #b   */
    GGraphNode *container;                  /* Conteneur à positionner     */

    base = G_GRAPH_NODE(node);

    g_flow_block_get_boundary(node->block, NULL, &last);

    switch (node->exits_count)
    {
        case 0:
            break;

        case 1:

            if (node->exits[0].type == ILT_LOOP)
                break;

            target = G_FLOW_NODE(find_node_for_instruction(nodes, node->exits[0].instr));

            dest_slot = g_flow_node_get_slot(target, true,
                                             last, node->exits[0].group_index);

            pos.direct_x = g_flow_node_get_slot_offset(target, true, dest_slot);
            pos.direct_x = (G_GRAPH_NODE(target)->alloc.width / 2) - pos.direct_x;

            if (target->entries_count == 1)
                g_graph_node_set_pending_position(G_GRAPH_NODE(target), PPF_DIRECT_X, pos, base);

            break;

        case 2:

            target_a = G_FLOW_NODE(find_node_for_instruction(nodes, node->exits[0].instr));
            target_b = G_FLOW_NODE(find_node_for_instruction(nodes, node->exits[1].instr));

            rank_a = g_flow_node_get_rank(target_a);
            rank_b = g_flow_node_get_rank(target_b);

            if (rank_a == rank_b)
                break;

            /* Alignement d'un bloc lié */

            if (rank_a > rank_b)
            {
                /* Seuil vertical pour un côté */

                container = g_graph_node_find_container_at_same_level(nodes,
                                                                      G_GRAPH_NODE(node),
                                                                      G_GRAPH_NODE(target_b));

                if (container == NULL) container = G_GRAPH_NODE(target_b);

                pos.left_margin = g_flow_node_get_slot_offset(node, false, &node->exits[0]);
                g_graph_node_set_pending_position(container, PPF_LEFT_MARGIN, pos, base);

                /* Trait vertical de l'autre côté... */

                pos.direct_x = pos.left_margin;

                dest_slot = g_flow_node_get_slot(target_a, true,
                                                 last, node->exits[0].group_index);

                pos.direct_x -= g_flow_node_get_slot_offset(target_a, true, dest_slot);

                g_graph_node_set_pending_position(G_GRAPH_NODE(target_a), PPF_DIRECT_X, pos, base);

            }
            else
            {
                /* Seuil vertical pour un côté */

                container = g_graph_node_find_container_at_same_level(nodes,
                                                                      G_GRAPH_NODE(node),
                                                                      G_GRAPH_NODE(target_a));

                if (container == NULL) container = G_GRAPH_NODE(target_a);

                pos.right_margin = g_flow_node_get_slot_offset(node, false, &node->exits[1]);
                g_graph_node_set_pending_position(container, PPF_RIGHT_MARGIN, pos, base);

                /* Trait vertical de l'autre côté... */

                pos.direct_x = pos.right_margin;

                dest_slot = g_flow_node_get_slot(target_b, true,
                                                 last, node->exits[1].group_index);

                pos.direct_x -= g_flow_node_get_slot_offset(target_b, true, dest_slot);

                g_graph_node_set_pending_position(G_GRAPH_NODE(target_b), PPF_DIRECT_X, pos, base);

            }

            break;

    }

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node     = noeud graphique démarrant la visite.              *
*                callback = ensemble de blocs à parcourir.                    *
*                data     = donnée utilisateur à associer au parcours.        *
*                                                                             *
*  Description : Parcourt tous les blocs d'instructions dans un ordre donné.  *
*                                                                             *
*  Retour      : true si le parcours a été jusqu'à son terme, false sinon.    *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_flow_node_visit_flow_nodes(GFlowNode *node, graph_node_visitor_cb callback, void *data)
{
    return callback(G_GRAPH_NODE(node), GVS_NODE, data);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node  = noeud graphique à consulter.                         *
*                instr = instruction à considérer.                            *
*                                                                             *
*  Description : Précise si le noeud a pour première instruction celle donnée.*
*                                                                             *
*  Retour      : true si la première instruction du noeud est celle indiquée. *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

bool g_flow_node_start_with(const GFlowNode *node, GArchInstruction *instr)
{
    GArchInstruction *first;                /* Première instr. du noeud    */

    g_flow_block_get_boundary(node->block, &first, NULL);

    /*
    do
    {
        vmpa_t a1, a2;

        g_arch_instruction_get_location(instr, NULL, NULL, &a1);
        g_arch_instruction_get_location(first, NULL, NULL, &a2);

        printf(" -- compare %p (0x%08lx) vs %p (0x%08lx)\n",
               instr, a1, first, a2);

    }
    while (0);
    */

    return (first == instr);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node  = noeud graphique à consulter.                         *
*                ranks = classement à mettre à jour.                          *
*                                                                             *
*  Description : Précise la hauteur minimale requise pour un noeud.           *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void g_flow_node_register_rank(const GFlowNode *node, GGraphRanks *ranks)
{
    unsigned int index;                     /* Indice du rang associé      */

    index = g_flow_node_get_rank(node);

    g_graph_ranks_set_min_height(ranks, index, G_GRAPH_NODE(node)->alloc.height);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node  = noeud graphique à mettre à jour.                     *
*                ranks = classement à consulter.                              *
*                                                                             *
*  Description : Définit l'ordonnée de l'espace attribué à un noeud.          *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void g_flow_node_apply_rank(GFlowNode *node, GGraphRanks *ranks)
{
    unsigned int index;                     /* Indice du rang associé      */

    index = g_flow_node_get_rank(node);

    G_GRAPH_NODE(node)->alloc.y = g_graph_ranks_get_y_for_rank(ranks, index);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node   = noeud graphique à mettre à jour.                    *
*                layout = disposition globale du graphique.                   *
*                nodes  = ensemble des noeuds en place.                       *
*                                                                             *
*  Description : Etablit les liaison entre un noeud et ses suivants.          *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void g_flow_node_link(GFlowNode *node, GGraphLayout *layout, GGraphNode *nodes)
{
    GArchInstruction *last;                 /* Dernière instr. du noeud    */
    size_t i;                               /* Boucle de parcours          */
    GFlowNode *target;                      /* Bloc visé par le lien       */
    node_slot_t *dest_slot;                 /* Accrochage d'arrivée        */
    EdgeColor color;                        /* Couleur du lien à créer     */
    GGraphEdge *edge;                       /* Lien à mettre en place      */

    g_flow_block_get_boundary(node->block, NULL, &last);

    for (i = 0; i < node->exits_count; i++)
    {
        target = G_FLOW_NODE(find_node_for_instruction(nodes, node->exits[i].instr));

        dest_slot = g_flow_node_get_slot(target, true,
                                         last, node->exits[i].group_index);

        switch (node->exits[i].type)
        {
            case ILT_JUMP_IF_TRUE:
                color = EGC_GREEN;
                break;
            case ILT_JUMP_IF_FALSE:
                color = EGC_RED;
                break;
            case ILT_LOOP:
                color = EGC_BLUE;
                break;
            case ILT_CATCH_EXCEPTION:
                color = EGC_DASHED_GRAY;
                break;
            default:
                color = EGC_DEFAULT;
                break;

        }

        edge = g_graph_edge_new(node, &node->exits[i], target, dest_slot, color);
        g_graph_layout_add_edge(layout, edge);

    }

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node = intermédiaire à consulter.                            *
*                view = support de destination.                               *
*                                                                             *
*  Description : Place un noeud sur son support final.                        *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void g_flow_node_place(const GFlowNode *node, GtkGraphView *view)
{
    printf("[put] %p (%d ; %d) - (%d ; %d)\n", node,
           G_GRAPH_NODE(node)->alloc.x, G_GRAPH_NODE(node)->alloc.y,
           G_GRAPH_NODE(node)->alloc.width, G_GRAPH_NODE(node)->alloc.height);

    gtk_graph_view_put(view, GTK_WIDGET(node->view), &G_GRAPH_NODE(node)->alloc);

}



/* ---------------------------------------------------------------------------------- */
/*                          GESTION DES ACCROCHES D'UN NOEUD                          */
/* ---------------------------------------------------------------------------------- */


/******************************************************************************
*                                                                             *
*  Paramètres  : node = intermédiaire à compléter.                            *
*                                                                             *
*  Description : Prépare les points d'entrées du noeud.                       *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_flow_node_setup_entry_slots(GFlowNode *node)
{
    GArchInstruction *first;                /* Première instr. du noeud    */
    GArchInstruction **instrs;              /* Instr. visée par une autre  */
    InstructionLinkType *types;             /* Type de lien entre lignes   */
    size_t icount;                          /* Nombre de liens de dest.    */
    size_t i;                               /* Boucle de parcours          */

    g_flow_block_get_boundary(node->block, &first, NULL);
    icount = g_arch_instruction_get_sources(first, &instrs, &types);

    node->entries = (node_slot_t *)calloc(icount, sizeof(node_slot_t));
    node->entries_count = icount;

    for (i = 0; i < icount; i++)
    {
        g_object_ref(instrs[i]);
        node->entries[i].instr = instrs[i];

        node->entries[i].type = types[i];
        node->entries[i].group_index = g_arch_instruction_compute_group_index(&instrs[i],
                                                                              instrs, icount);
        node->entries[i].slot_index = i;

    }

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node = intermédiaire à compléter.                            *
*                                                                             *
*  Description : Prépare les points de sorties du noeud.                      *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_flow_node_setup_exit_slots(GFlowNode *node)
{
    GArchInstruction *last;                 /* Dernière instr. du noeud    */
    GArchInstruction **instrs;              /* Instr. visée par une autre  */
    InstructionLinkType *types;             /* Type de lien entre lignes   */
    size_t icount;                          /* Nombre de liens de dest.    */
    size_t i;                               /* Boucle de parcours          */

    g_flow_block_get_boundary(node->block, NULL, &last);
    icount = g_arch_instruction_get_destinations(last, &instrs, &types, NULL);

    node->exits = (node_slot_t *)calloc(icount, sizeof(node_slot_t));
    node->exits_count = icount;

    for (i = 0; i < icount; i++)
    {
        g_object_ref(instrs[i]);
        node->exits[i].instr = instrs[i];

        node->exits[i].type = types[i];
        node->exits[i].group_index = g_arch_instruction_compute_group_index(&instrs[i],
                                                                            instrs, icount);
        node->exits[i].slot_index = i;

    }

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node  = noeud graphique à consulter.                         *
*                entry = indique le type d'accrochage recherché.              *
*                instr = instruction visée.                                   *
*                index = indice de groupe pour départager au besoin.          *
*                                                                             *
*  Description : Etablit un lien entre deux noeuds graphiques.                *
*                                                                             *
*  Retour      : Lien graphique mis en place.                                 *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static node_slot_t *g_flow_node_get_slot(const GFlowNode *node, bool entry, GArchInstruction *instr, size_t index)
{
    node_slot_t *result;                    /* Emplacement à retourner     */
    node_slot_t *list;                      /* Liste à parcourir           */
    size_t count;                           /* Taille de cette liste       */
    size_t i;                               /* Boucle de parcours          */

    if (entry)
    {
        list = node->entries;
        count = node->entries_count;
    }
    else
    {
        list = node->exits;
        count = node->exits_count;
    }

    for (i = 0; i < count; i++)
    {
        result = list + i;

        if (result->instr == instr/* && result->group_index == index*/)
            break;

    }

    return (i == count ? NULL : result);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node  = noeud graphique à consulter.                         *
*                entry = indique le type d'accrochage recherché.              *
*                slot  = accroche dont l'emplacement est à définir.           *
*                                                                             *
*  Description : Localise un point d'accroche à un noeud graphique.           *
*                                                                             *
*  Retour      : Décallage relatif pour l'accroche fournie.                   *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static gint g_flow_node_get_slot_offset(const GFlowNode *node, bool entry, const node_slot_t *slot)
{
    gint result;                            /* Valeur à retourner          */
    node_slot_t *slots;                     /* Accroches à parcourir       */
    size_t count;                           /* Nombre de ces points        */
    gint slots_width;                       /* Largeur des accroches       */
    gint slots_left;                        /* Abscisse de la première     */
    size_t index;                           /* Indice de l'accroche visée  */

    if (entry)
    {
        slots = node->entries;
        count = node->entries_count;
    }
    else
    {
        slots = node->exits;
        count = node->exits_count;
    }

    slots_width = (count - 1) * SPACE_BETWEEN_SLOT;
    slots_left = (G_GRAPH_NODE(node)->alloc.width - slots_width) / 2;

    index = (slot - slots);
    /* BUG_ON(index >= count); */

    result = slots_left + index * SPACE_BETWEEN_SLOT;

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : node  = noeud graphique à consulter.                         *
*                entry = indique le type d'accrochage recherché.              *
*                slot  = accroche dont l'emplacement est à définir.           *
*                                                                             *
*  Description : Localise un point d'accroche à un noeud graphique.           *
*                                                                             *
*  Retour      : Emplacement réservé pour l'accroche fournie.                 *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GdkPoint g_flow_node_get_point_from_slot(const GFlowNode *node, bool entry, const node_slot_t *slot)
{
    GGraphNode *base;                       /* Accès rapides               */
    GdkPoint result;                        /* Position à retourner        */
    node_slot_t *slots;                     /* Accroches à parcourir       */
    size_t count;                           /* Nombre de ces points        */
    gint slots_width;                       /* Largeur des accroches       */
    gint slots_left;                        /* Abscisse de la première     */
    size_t index;                           /* Indice de l'accroche visée  */

    base = G_GRAPH_NODE(node);

    if (entry)
    {
        result.y = base->alloc.y;

        slots = node->entries;
        count = node->entries_count;

    }
    else
    {
        result.y = base->alloc.y + base->alloc.height;

        slots = node->exits;
        count = node->exits_count;

    }


    slots_width = (count - 1) * SPACE_BETWEEN_SLOT;
    slots_left = base->alloc.x + (base->alloc.width - slots_width) / 2;

    index = (slot - slots)/* / sizeof(node_slot_t)*/;
    /* BUG_ON(index >= count); */

    result.x = slots_left + index * SPACE_BETWEEN_SLOT;



#if 0
    slots_width = (count - 1) * SPACE_BETWEEN_SLOT;
    slots_left = base->alloc.x + (base->alloc.width - slots_width) / 2;

    index = (slot - slots)/* / sizeof(node_slot_t)*/;
    /* BUG_ON(index >= count); */

    result.x = slots_left + index * SPACE_BETWEEN_SLOT;
#endif
    return result;

}