diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2021-08-08 18:24:21 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2021-08-08 18:24:21 (GMT) |
commit | c0cc928bfab0af2cdbf16e9a04d41983f4732b93 (patch) | |
tree | eb62ba48bae31886ddad2385c2ccfbc1e002ec6f /src/arch/operand.c | |
parent | 1b7c29ed7dd9561a387be694f09c089e6126716c (diff) |
Introduce singletons for operands.
Diffstat (limited to 'src/arch/operand.c')
-rw-r--r-- | src/arch/operand.c | 227 |
1 files changed, 223 insertions, 4 deletions
diff --git a/src/arch/operand.c b/src/arch/operand.c index 3758d7f..66af6d2 100644 --- a/src/arch/operand.c +++ b/src/arch/operand.c @@ -33,12 +33,11 @@ #include "storage.h" #include "../common/sort.h" #include "../core/logs.h" +#include "../glibext/singleton-int.h" -/* ---------------------------------------------------------------------------------- */ -/* DEFINITION D'OPERANDE QUELCONQUE */ -/* ---------------------------------------------------------------------------------- */ +/* ------------------------ DEFINITION D'OPERANDE QUELCONQUE ------------------------ */ /* Initialise la classe générique des opérandes. */ @@ -47,6 +46,9 @@ static void g_arch_operand_class_init(GArchOperandClass *); /* Initialise une instance d'opérande d'architecture. */ static void g_arch_operand_init(GArchOperand *); +/* Procède à l'initialisation de l'interface de singleton. */ +static void g_arch_operand_singleton_interface_init(GSingletonCandidateInterface *); + /* Supprime toutes les références externes. */ static void g_arch_operand_dispose(GArchOperand *); @@ -55,6 +57,29 @@ static void g_arch_operand_finalize(GArchOperand *); +/* ------------------------ CONTROLE DU VOLUME DES INSTANCES ------------------------ */ + + +/* Fournit une liste de candidats embarqués par un candidat. */ +static GArchOperand **g_arch_operand_list_inner_instances(const GArchOperand *, size_t *); + +/* Met à jour une liste de candidats embarqués par un candidat. */ +static void g_arch_operand_update_inner_instances(GArchOperand *, GArchOperand **, size_t); + +/* Fournit l'empreinte d'un candidat à une centralisation. */ +static guint g_arch_operand_hash(const GArchOperand *); + +/* Détermine si deux candidats à l'unicité sont identiques. */ +static gboolean g_arch_operand_is_equal(const GArchOperand *, const GArchOperand *); + +/* Marque un candidat comme figé. */ +static void g_arch_operand_set_read_only(GArchOperand *); + +/* Indique si le candidat est figé. */ +static bool g_arch_operand_is_read_only(GArchOperand *); + + + /* --------------------- TRANSPOSITIONS VIA CACHE DES OPERANDES --------------------- */ @@ -67,7 +92,8 @@ static bool g_arch_operand_serialize(const GArchOperand *, GAsmStorage *, packed /* Indique le type défini pour un opérande d'architecture. */ -G_DEFINE_TYPE(GArchOperand, g_arch_operand, G_TYPE_OBJECT); +G_DEFINE_TYPE_WITH_CODE(GArchOperand, g_arch_operand, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE(G_TYPE_SINGLETON_CANDIDATE, g_arch_operand_singleton_interface_init)); @@ -121,6 +147,32 @@ static void g_arch_operand_init(GArchOperand *operand) /****************************************************************************** * * +* Paramètres : iface = interface GLib à initialiser. * +* * +* Description : Procède à l'initialisation de l'interface de singleton. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arch_operand_singleton_interface_init(GSingletonCandidateInterface *iface) +{ + iface->list_inner = (list_inner_instances_fc)g_arch_operand_list_inner_instances; + iface->update_inner = (update_inner_instances_fc)g_arch_operand_update_inner_instances; + + iface->hash = (hash_candidate_fc)g_arch_operand_hash; + iface->is_equal = (is_candidate_equal_fc)g_arch_operand_is_equal; + + iface->set_ro = (set_candidate_ro_fc)g_arch_operand_set_read_only; + iface->is_ro = (is_candidate_ro_fc)g_arch_operand_is_read_only; + +} + + +/****************************************************************************** +* * * Paramètres : operand = instance d'objet GLib à traiter. * * * * Description : Supprime toutes les références externes. * @@ -305,6 +357,173 @@ char *g_arch_operand_build_tooltip(const GArchOperand *operand, const GLoadedBin /* ---------------------------------------------------------------------------------- */ +/* CONTROLE DU VOLUME DES INSTANCES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* count = quantité d'instances à l'unicité internes. * +* * +* Description : Fournit une liste de candidats embarqués par un candidat. * +* * +* Retour : Liste de candidats internes ou NULL si aucun. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static GArchOperand **g_arch_operand_list_inner_instances(const GArchOperand *operand, size_t *count) +{ + GArchOperand **result; /* Instances à retourner */ + GArchOperandClass *class; /* Classe associée à l'objet */ + + class = G_ARCH_OPERAND_GET_CLASS(operand); + + if (class->list_inner == NULL) + { + *count = 0; + result = NULL; + } + + else + result = class->list_inner(operand, count); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* instances = liste de candidats internes devenus singletons. * +* count = quantité d'instances à l'unicité internes. * +* * +* Description : Met à jour une liste de candidats embarqués par un candidat. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arch_operand_update_inner_instances(GArchOperand *operand, GArchOperand **instances, size_t count) +{ + GArchOperandClass *class; /* Classe associée à l'objet */ + + class = G_ARCH_OPERAND_GET_CLASS(operand); + + if (class->update_inner == NULL) + assert(class->list_inner == NULL); + + else + { + assert(class->list_inner != NULL); + class->update_inner(operand, instances, count); + } + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* * +* Description : Fournit l'empreinte d'un candidat à une centralisation. * +* * +* Retour : Empreinte de l'élément représenté. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static guint g_arch_operand_hash(const GArchOperand *operand) +{ + guint result; /* Valeur à retourner */ + GArchOperandClass *class; /* Classe associée à l'objet */ + + class = G_ARCH_OPERAND_GET_CLASS(operand); + + result = class->hash(operand); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* other = second élément à analyser. * +* * +* Description : Détermine si deux candidats à l'unicité sont identiques. * +* * +* Retour : Bilan de la comparaison. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static gboolean g_arch_operand_is_equal(const GArchOperand *operand, const GArchOperand *other) +{ + gboolean result; /* Bilan à renvoyer */ + int ret; /* Bilan d'une comparaison */ + + ret = g_arch_operand_compare(operand, other); + + result = (ret == 0); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* * +* Description : Marque un candidat comme figé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_arch_operand_set_read_only(GArchOperand *operand) +{ + operand->read_only = true; + +} + + +/****************************************************************************** +* * +* Paramètres : operand = objet dont l'instance se veut unique. * +* * +* Description : Indique si le candidat est figé. * +* * +* Retour : true si le contenu du candidat ne peut plus être modifié. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_arch_operand_is_read_only(GArchOperand *operand) +{ + bool result; /* Etat à retourner */ + + result = operand->read_only; + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ /* TRANSPOSITIONS VIA CACHE DES OPERANDES */ /* ---------------------------------------------------------------------------------- */ |