diff options
| author | Cyrille Bagard <nocbos@gmail.com> | 2014-10-07 22:07:27 (GMT) | 
|---|---|---|
| committer | Cyrille Bagard <nocbos@gmail.com> | 2014-10-07 22:07:27 (GMT) | 
| commit | a5e162d47a574f334b172dfee3128a40e8d52fb3 (patch) | |
| tree | 5816a46365d196f40ac39fed884a9ee20fb44194 /src/arch/register.c | |
| parent | 1d5f7f28f92251dc4d3bff8d87b3e3052ab9cab2 (diff) | |
Created a compiler for architecture instruction definitions.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@410 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/arch/register.c')
| -rw-r--r-- | src/arch/register.c | 202 | 
1 files changed, 202 insertions, 0 deletions
diff --git a/src/arch/register.c b/src/arch/register.c index 389e71a..706fcd4 100644 --- a/src/arch/register.c +++ b/src/arch/register.c @@ -28,6 +28,9 @@ +/* ---------------------------- PUR REGISTRE DU MATERIEL ---------------------------- */ + +  /* Initialise la classe des registres. */  static void g_arch_register_class_init(GArchRegisterClass *); @@ -36,6 +39,28 @@ static void g_arch_register_init(GArchRegister *); +/* ------------------------- REGISTRE SOUS FORME D'OPERANDE ------------------------- */ + + +/* Initialise la classe des opérandes de registre. */ +static void g_register_operand_class_init(GRegisterOperandClass *); + +/* Initialise une instance d'opérande de registre. */ +static void g_register_operand_init(GRegisterOperand *); + +/* Compare un opérande avec un autre. */ +static bool g_register_operand_compare(const GRegisterOperand *, const GRegisterOperand *); + +/* Traduit un opérande en version humainement lisible. */ +static void g_register_operand_print(const GRegisterOperand *, GBufferLine *, AsmSyntax); + + + +/* ---------------------------------------------------------------------------------- */ +/*                              PUR REGISTRE DU MATERIEL                              */ +/* ---------------------------------------------------------------------------------- */ + +  /* Indique le type défini pour une représentation d'un registre. */  G_DEFINE_TYPE(GArchRegister, g_arch_register, G_TYPE_OBJECT); @@ -210,3 +235,180 @@ bool g_arch_register_is_stack_pointer(const GArchRegister *reg)      return result;  } + + + +/* ---------------------------------------------------------------------------------- */ +/*                           REGISTRE SOUS FORME D'OPERANDE                           */ +/* ---------------------------------------------------------------------------------- */ + + +/* Indique le type défini par la GLib pour un opérande de registre Dalvik. */ +G_DEFINE_TYPE(GRegisterOperand, g_register_operand, G_TYPE_ARCH_OPERAND); + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : klass = classe à initialiser.                                * +*                                                                             * +*  Description : Initialise la classe des opérandes de registre Dalvik.       * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_register_operand_class_init(GRegisterOperandClass *klass) +{ + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = instance à initialiser.                            * +*                                                                             * +*  Description : Initialise une instance d'opérande de registre Dalvik.       * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_register_operand_init(GRegisterOperand *operand) +{ +    GArchOperand *parent;                   /* Instance parente            */ + +    parent = G_ARCH_OPERAND(operand); + +    parent->compare = (operand_compare_fc)g_register_operand_compare; +    parent->print = (operand_print_fc)g_register_operand_print; + +    operand->is_written = false; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : reg = registre déjà en place.                                * +*                                                                             * +*  Description : Crée un opérande visant un registre.                         * +*                                                                             * +*  Retour      : Opérande mis en place.                                       * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchOperand *g_register_operand_new(GArchRegister *reg) +{ +    GRegisterOperand *result;         /* Structure à retourner       */ + +    result = g_object_new(G_TYPE_REGISTER_OPERAND, NULL); + +    result->reg = reg; + +    return G_ARCH_OPERAND(result); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande représentant un registre.                 * +*                                                                             * +*  Description : Fournit le registre Dalvik associé à l'opérande.             * +*                                                                             * +*  Retour      : Représentation interne du registre.                          * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +GArchRegister *g_register_operand_get_register(const GRegisterOperand *operand) +{ +    return operand->reg; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : a = premier opérande à consulter.                            * +*                b = second opérande à consulter.                             * +*                                                                             * +*  Description : Compare un opérande avec un autre.                           * +*                                                                             * +*  Retour      : Bilan de la comparaison.                                     * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static bool g_register_operand_compare(const GRegisterOperand *a, const GRegisterOperand *b) +{ +    return (g_arch_register_compare(a->reg, b->reg) == 0); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande à traiter.                                * +*                line    = ligne tampon où imprimer l'opérande donné.         * +*                syntax  = type de représentation demandée.                   * +*                                                                             * +*  Description : Traduit un opérande en version humainement lisible.          * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +static void g_register_operand_print(const GRegisterOperand *operand, GBufferLine *line, AsmSyntax syntax) +{ +    g_arch_register_print(operand->reg, line, syntax); + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande représentant un registre à mettre à jour. * +*                                                                             * +*  Description : Marque l'opérande comme étant écrit plutôt que consulté.     * +*                                                                             * +*  Retour      : -                                                            * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +void g_register_operand_mark_as_written(GRegisterOperand *operand) +{ +    operand->is_written = true; + +} + + +/****************************************************************************** +*                                                                             * +*  Paramètres  : operand = opérande représentant un registre à consulter.     * +*                                                                             * +*  Description : Indique le type d'accès réalisé sur l'opérande.              * +*                                                                             * +*  Retour      : Type d'accès : true en cas d'écriture, false sinon.          * +*                                                                             * +*  Remarques   : -                                                            * +*                                                                             * +******************************************************************************/ + +bool g_register_operand_is_written(const GRegisterOperand *operand) +{ +    return operand->is_written; + +}  | 
