diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-10-29 11:37:13 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-10-29 11:37:13 (GMT) |
commit | 38e455ebbbbf90ddbf552f95a1dfb3c544907587 (patch) | |
tree | c6e2a4763baef01c87dd0954116fb2c457e10c23 /src/arch/arm | |
parent | 8c71b36d401b2473342daddcb9b7eb4b83ba3295 (diff) |
Reduced once again the size of the main instruction structure.
Diffstat (limited to 'src/arch/arm')
-rw-r--r-- | src/arch/arm/instruction-int.h | 3 | ||||
-rw-r--r-- | src/arch/arm/instruction.c | 65 | ||||
-rw-r--r-- | src/arch/arm/instruction.h | 3 | ||||
-rw-r--r-- | src/arch/arm/v7/instruction.c | 51 | ||||
-rw-r--r-- | src/arch/arm/v7/instruction.h | 3 | ||||
-rw-r--r-- | src/arch/arm/v7/opdefs/Makefile.am | 2 |
6 files changed, 104 insertions, 23 deletions
diff --git a/src/arch/arm/instruction-int.h b/src/arch/arm/instruction-int.h index 0dc848d..ba93b03 100644 --- a/src/arch/arm/instruction-int.h +++ b/src/arch/arm/instruction-int.h @@ -36,6 +36,9 @@ struct _GArmInstruction GArchInstruction parent; /* A laisser en premier */ const char *keyword; /* Nom clef de l'instruction */ + char *suffix; /* Complément au nom affiché */ + char *cached_keyword; /* Désignation complète */ + ArmCondCode cond; /* Condition d'exécution */ }; diff --git a/src/arch/arm/instruction.c b/src/arch/arm/instruction.c index 2c1f3b8..4c08c9a 100644 --- a/src/arch/arm/instruction.c +++ b/src/arch/arm/instruction.c @@ -24,6 +24,7 @@ #include "instruction.h" +#include <malloc.h> #include <string.h> @@ -44,8 +45,8 @@ static void g_arm_instruction_dispose(GArmInstruction *); /* Procède à la libération totale de la mémoire. */ static void g_arm_instruction_finalize(GArmInstruction *); -/* Reconstruit le cache complet d'une désignation d'instruction. */ -static void g_arm_instruction_build_keyword(const GArmInstruction *, AsmSyntax); +/* Fournit le nom humain de l'instruction manipulée. */ +static const char *g_arm_instruction_get_keyword(GArmInstruction *, AsmSyntax); @@ -76,7 +77,7 @@ static void g_arm_instruction_class_init(GArmInstructionClass *klass) object_class->dispose = (GObjectFinalizeFunc/* ! */)g_arm_instruction_dispose; object_class->finalize = (GObjectFinalizeFunc)g_arm_instruction_finalize; - instr->build_key = (build_instruction_keyword_fc)g_arm_instruction_build_keyword; + instr->get_keyword = (get_instruction_keyword_fc)g_arm_instruction_get_keyword; } @@ -133,6 +134,12 @@ static void g_arm_instruction_dispose(GArmInstruction *instr) static void g_arm_instruction_finalize(GArmInstruction *instr) { + if (instr->suffix != NULL) + free(instr->suffix); + + if (instr->cached_keyword != NULL) + free(instr->cached_keyword); + G_OBJECT_CLASS(g_arm_instruction_parent_class)->finalize(G_OBJECT(instr)); } @@ -140,10 +147,38 @@ static void g_arm_instruction_finalize(GArmInstruction *instr) /****************************************************************************** * * -* Paramètres : instr = instruction à traiter. * +* Paramètres : instr = instruction quelconque à modifier. * +* suffix = chaîne de caractères fournie en complément. * +* * +* Description : Etend la désignation d'un nom d'instruction. * +* * +* Retour : true. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_arm_instruction_extend_keyword(GArmInstruction *instr, const char *suffix) +{ + instr->suffix = stradd(instr->suffix, suffix); + + if (instr->cached_keyword != NULL) + { + free(instr->cached_keyword); + instr->cached_keyword = NULL; + } + + return true; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'assemblage à consulter. * * syntax = type de représentation demandée. * * * -* Description : Reconstruit le cache complet d'une désignation d'instruction.* +* Description : Fournit le nom humain de l'instruction manipulée. * * * * Retour : Mot clef de bas niveau. * * * @@ -151,20 +186,18 @@ static void g_arm_instruction_finalize(GArmInstruction *instr) * * ******************************************************************************/ -static void g_arm_instruction_build_keyword(const GArmInstruction *instr, AsmSyntax syntax) +static const char *g_arm_instruction_get_keyword(GArmInstruction *instr, AsmSyntax syntax) { - GArchInstruction *base; /* Instruction, vue générique */ - - /* FIXME : tout bouger dans la base des instructions ? */ + if (instr->cached_keyword == NULL) + { + instr->cached_keyword = strdup(instr->keyword); - base = G_ARCH_INSTRUCTION(instr); + if (instr->suffix != NULL) + instr->cached_keyword = stradd(instr->cached_keyword, instr->suffix); - base->cached_keyword = strdup(instr->keyword); + } - /* - if (base->suffix != NULL) - base->cached_keyword = stradd(base->cached_keyword, base->suffix); - */ + return instr->cached_keyword; } @@ -210,7 +243,7 @@ bool g_arm_instruction_set_cond(GArmInstruction *instr, ArmCondCode cond) } if (suffix != NULL) - result = g_arch_instruction_extend_keyword(G_ARCH_INSTRUCTION(instr), suffix); + result = g_arm_instruction_extend_keyword(instr, suffix); else result = true; diff --git a/src/arch/arm/instruction.h b/src/arch/arm/instruction.h index 3211766..946d272 100644 --- a/src/arch/arm/instruction.h +++ b/src/arch/arm/instruction.h @@ -53,6 +53,9 @@ typedef struct _GArmInstructionClass GArmInstructionClass; /* Indique le type défini pour une représentation d'une instruction ARM. */ GType g_arm_instruction_get_type(void); +/* Etend la désignation d'un nom d'instruction. */ +bool g_arm_instruction_extend_keyword(GArmInstruction *, const char *); + /* Définit les conditions d'exécution d'une instruction ARM. */ bool g_arm_instruction_set_cond(GArmInstruction *, ArmCondCode); diff --git a/src/arch/arm/v7/instruction.c b/src/arch/arm/v7/instruction.c index d485dbc..0fba9cb 100644 --- a/src/arch/arm/v7/instruction.c +++ b/src/arch/arm/v7/instruction.c @@ -24,6 +24,12 @@ #include "instruction.h" +#include <assert.h> +#ifndef NDEBUG +# include <string.h> +#endif + + #include "../instruction-int.h" @@ -33,6 +39,8 @@ struct _GArmV7Instruction { GArmInstruction parent; /* Instance parente */ + char encoding; /* Encodage de l'instruction */ + bool setflags; /* Mise à jour des drapeaux */ }; @@ -190,14 +198,22 @@ GArchInstruction *g_armv7_instruction_new(const char *keyword) static const char *g_armv7_instruction_get_encoding(const GArmV7Instruction *instr) { const char *result; /* Description à retourner */ - const char *raw; /* Description brute d'origine */ - raw = G_ARCH_INSTRUCTION(instr)->encoding; + switch (instr->encoding) + { + case 't': + result = "Thumb/16"; + break; - if (raw[0] == 'T' || raw[0] == 't') - result = "Thumb"; - else - result = "ARM"; + case 'T': + result = "Thumb/32"; + break; + + default: + result = "ARM"; + break; + + } return result; @@ -206,6 +222,29 @@ static const char *g_armv7_instruction_get_encoding(const GArmV7Instruction *ins /****************************************************************************** * * +* Paramètres : instr = instruction quelconque à modifier. * +* encoding = encodage de l'instruction. * +* * +* Description : Précise l'encodage d'une instruction ARMv7 dans le détail. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_armv7_instruction_set_encoding(GArmV7Instruction *instr, const char *encoding) +{ + assert(strlen(encoding) == 1); + assert(encoding[0] == 'A' || encoding[0] == 'T' || encoding[0] == 't'); + + instr->encoding = encoding[0]; + +} + + +/****************************************************************************** +* * * Paramètres : instr = instruction ARMv7 à mettre à jour. * * set = statut à enregistrer. * * * diff --git a/src/arch/arm/v7/instruction.h b/src/arch/arm/v7/instruction.h index 291f2c9..5d79cb8 100644 --- a/src/arch/arm/v7/instruction.h +++ b/src/arch/arm/v7/instruction.h @@ -55,6 +55,9 @@ GType g_armv7_instruction_get_type(void); /* Crée une instruction pour l'architecture ARMv7. */ GArchInstruction *g_armv7_instruction_new(const char *); +/* Précise l'encodage d'une instruction ARMv7 dans le détail. */ +void g_armv7_instruction_set_encoding(GArmV7Instruction *, const char *); + /* Définit si une instruction ARMv7 met à jour les drapeaux. */ bool g_armv7_instruction_define_setflags(GArmV7Instruction *, bool); diff --git a/src/arch/arm/v7/opdefs/Makefile.am b/src/arch/arm/v7/opdefs/Makefile.am index 7844578..41785c6 100644 --- a/src/arch/arm/v7/opdefs/Makefile.am +++ b/src/arch/arm/v7/opdefs/Makefile.am @@ -24,7 +24,7 @@ D2C_MACROS = \ -M SignExtend=sign_extend_armv7_imm \ -M SetInsFlag=g_arch_instruction_set_flag \ -M StoreCondition=g_arm_instruction_set_cond \ - -M ExtendKeyword=g_arch_instruction_extend_keyword + -M ExtendKeyword=g_arm_instruction_extend_keyword D2C_OPERANDS = \ -n BarrierLimitation \ |