diff options
Diffstat (limited to 'src/core/processors.c')
-rw-r--r-- | src/core/processors.c | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/src/core/processors.c b/src/core/processors.c index 3211009..e4a558f 100644 --- a/src/core/processors.c +++ b/src/core/processors.c @@ -24,6 +24,7 @@ #include "processors.h" +#include <assert.h> #include <malloc.h> #include <pthread.h> #include <string.h> @@ -37,6 +38,9 @@ +/* Cache des singletons d'opérandes */ +static GSingletonFactory *__operands_factory = NULL; + /* Caractéristiques d'un processeur */ typedef struct _proc_t { @@ -85,6 +89,74 @@ void register_arch_gtypes(void) /****************************************************************************** * * +* Paramètres : - * +* * +* Description : Met en place le fournisseur d'instances uniques d'opérandes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void init_operands_factory(void) +{ + assert(__operands_factory == NULL); + + __operands_factory = g_singleton_factory_new(); + +} + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Fournit l'usine à opérandes pour toutes les instructions. * +* * +* Retour : Producteur d'instances uniques. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GSingletonFactory *get_operands_factory(void) +{ + GSingletonFactory *result; /* Usine à renvoyer */ + + result = __operands_factory; + + g_object_ref(G_OBJECT(result)); + + return result; + +} + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Supprime le fournisseur d'instances uniques d'opérandes. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void exit_operands_factory(void) +{ + assert(__operands_factory != NULL); + + g_clear_object(&__operands_factory); + +} + + +/****************************************************************************** +* * * Paramètres : type = type GLib représentant le type à instancier. * * * * Description : Enregistre un processeur pour une architecture donnée. * @@ -113,7 +185,10 @@ bool register_processor_type(GType type) new = find_processor_by_key(key); - if (new == NULL) + if (new != NULL) + free(key); + + else { _processors_definitions = realloc(_processors_definitions, ++_processors_definitions_count * sizeof(proc_t)); |