diff options
Diffstat (limited to 'src/arch/raw.c')
-rw-r--r-- | src/arch/raw.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/src/arch/raw.c b/src/arch/raw.c index 36bb4b3..4ae1e11 100644 --- a/src/arch/raw.c +++ b/src/arch/raw.c @@ -77,6 +77,22 @@ static const char *g_raw_instruction_get_encoding(const GRawInstruction *); /* Fournit le nom humain de l'instruction manipulée. */ static const char *g_raw_instruction_get_keyword(const GRawInstruction *, AsmSyntax); + + +/* -------------------- CONSERVATION SUR DISQUE DES INSTRUCTIONS -------------------- */ + + +/* Charge une instruction depuis une mémoire tampon. */ +static bool g_raw_instruction_unserialize(GRawInstruction *, GAsmStorage *, GBinFormat *, packed_buffer *); + +/* Sauvegarde une instruction dans une mémoire tampon. */ +static bool g_raw_instruction_serialize(GRawInstruction *, GAsmStorage *, packed_buffer *); + + + +/* ------------------------ OFFRE DE CAPACITES DE GENERATION ------------------------ */ + + /* Ajoute à un tampon GLib le contenu de l'instance spécifiée. */ static void g_raw_instruction_print(GRawInstruction *, GBufferLine *, size_t, size_t, const GBinContent *); @@ -117,6 +133,10 @@ static void g_raw_instruction_class_init(GRawInstructionClass *klass) instr->get_encoding = (get_instruction_encoding_fc)g_raw_instruction_get_encoding; instr->get_keyword = (get_instruction_keyword_fc)g_raw_instruction_get_keyword; + + instr->unserialize = (unserialize_instruction_fc)g_raw_instruction_unserialize; + instr->serialize = (serialize_instruction_fc)g_raw_instruction_serialize; + instr->print = (print_instruction_fc)g_raw_instruction_print; } @@ -475,6 +495,107 @@ static const char *g_raw_instruction_get_keyword(const GRawInstruction *instr, A } + +/* ---------------------------------------------------------------------------------- */ +/* CONSERVATION SUR DISQUE DES INSTRUCTIONS */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'assemblage à consulter. * +* storage = mécanisme de sauvegarde à manipuler. * +* format = format binaire chargé associé à l'architecture. * +* pbuf = zone tampon à remplir. * +* * +* Description : Charge une instruction depuis une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_raw_instruction_unserialize(GRawInstruction *instr, GAsmStorage *storage, GBinFormat *format, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchInstructionClass *parent; /* Classe parente à consulter */ + uint8_t boolean; /* Valeur booléenne */ + + parent = G_ARCH_INSTRUCTION_CLASS(g_raw_instruction_parent_class); + + result = parent->unserialize(G_ARCH_INSTRUCTION(instr), storage, format, pbuf); + + if (result) + { + result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false); + + if (result) + instr->is_padding = (boolean == 1 ? true : false); + + } + + if (result) + { + result = extract_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false); + + if (result) + instr->is_string = (boolean == 1 ? true : false); + + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : instr = instruction d'assemblage à consulter. * +* storage = mécanisme de sauvegarde à manipuler. * +* pbuf = zone tampon à remplir. * +* * +* Description : Sauvegarde une instruction dans une mémoire tampon. * +* * +* Retour : Bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static bool g_raw_instruction_serialize(GRawInstruction *instr, GAsmStorage *storage, packed_buffer *pbuf) +{ + bool result; /* Bilan à retourner */ + GArchInstructionClass *parent; /* Classe parente à consulter */ + uint8_t boolean; /* Valeur booléenne */ + + parent = G_ARCH_INSTRUCTION_CLASS(g_raw_instruction_parent_class); + + result = parent->serialize(G_ARCH_INSTRUCTION(instr), storage, pbuf); + + if (result) + { + boolean = (instr->is_padding ? 1 : 0); + result = extend_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false); + } + + if (result) + { + boolean = (instr->is_string ? 1 : 0); + result = extend_packed_buffer(pbuf, &boolean, sizeof(uint8_t), false); + } + + return result; + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* OFFRE DE CAPACITES DE GENERATION */ +/* ---------------------------------------------------------------------------------- */ + + /****************************************************************************** * * * Paramètres : instr = instruction d'assemblage à représenter. * |