/* Chrysalide - Outil d'analyse de fichiers binaires * asm.c - sorties en langage d'assemblage * * Copyright (C) 2010-2012 Cyrille Bagard * * This file is part of Chrysalide. * * Chrysalide is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Chrysalide is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Foobar. If not, see . */ #include "asm.h" #include "../output-int.h" #include "../../analysis/type.h" /* TODO : remme */ /* Sortie selon le langage d'assemblage (instance) */ struct _GAsmOutput { GLangOutput parent; /* A laisser en premier */ }; /* Sortie selon le langage d'assemblage (classe) */ struct _GAsmOutputClass { GLangOutputClass parent; /* A laisser en premier */ }; /* Initialise la classe des sorties en langage d'assemblage. */ static void g_asm_output_class_init(GAsmOutputClass *); /* Initialise une instance de sortie en langage d'assemblage. */ static void g_asm_output_init(GAsmOutput *); /* Ajoute un commentaire à un tampon donné. */ static GBufferLine *g_asm_output_write_comments(GAsmOutput *, GCodeBuffer *, const char *, size_t); /* Imprime dans un tampon donné une méthode de comparaison. */ static void g_asm_output_write_comp_sign(GAsmOutput *, GBufferLine *, CompSignType); /* Débute la documentation d'une routine. */ static GBufferLine *g_asm_output_start_routine_info(const GAsmOutput *, GCodeBuffer *); /* Débute la définition d'une routine. */ static GBufferLine *g_asm_output_start_routine_prototype(GAsmOutput *, GCodeBuffer *, const GDataType *); /* Termine la définition d'une routine. */ static void g_asm_output_end_routine_prototype(GAsmOutput *, GCodeBuffer *, GBufferLine *); /* Indique le type défini pour une sortie en langage d'assemblage. */ G_DEFINE_TYPE(GAsmOutput, g_asm_output, G_TYPE_LANG_OUTPUT); /****************************************************************************** * * * Paramètres : klass = classe à initialiser. * * * * Description : Initialise la classe des sorties en langage d'assemblage. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_asm_output_class_init(GAsmOutputClass *klass) { } /****************************************************************************** * * * Paramètres : output = instance à initialiser. * * * * Description : Initialise une instance de sortie en langage d'assemblage. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_asm_output_init(GAsmOutput *output) { GLangOutput *lang; /* Autre version de l'objet */ lang = G_LANG_OUTPUT(output); lang->cont_comments = (write_comments_fc)g_asm_output_write_comments; lang->write_comments = (write_comments_fc)g_asm_output_write_comments; lang->comp_sign = (write_comp_sign_fc)g_asm_output_write_comp_sign; lang->start_info = (start_rtn_info_fc)g_asm_output_start_routine_info; lang->start_routine_proto = (rlgbuftp_fc)g_asm_output_start_routine_prototype; lang->end_routine_proto = (lgbufln_fc)g_asm_output_end_routine_prototype; } /****************************************************************************** * * * Paramètres : - * * * * Description : Crée une nouvelle sortie en langage d'assemblage. * * * * Retour : Imprimeur créé. * * * * Remarques : - * * * ******************************************************************************/ GLangOutput *g_asm_output_new(void) { GBufferLine *result; /* Composant à retourner */ result = g_object_new(G_TYPE_ASM_OUTPUT, NULL); return G_LANG_OUTPUT(result); } /****************************************************************************** * * * Paramètres : output = encadrant de l'impression en langage de prog. * * buffer = tampon de sortie à disposition. * * text = texte à insérer dans l'existant. * * length = taille du texte à traiter. * * * * Description : Ajoute un commentaire à un tampon donné. * * * * Retour : Ligne nouvellement créée. * * * * Remarques : - * * * ******************************************************************************/ static GBufferLine *g_asm_output_write_comments(GAsmOutput *output, GCodeBuffer *buffer, const char *text, size_t length) { GBufferLine *result; /* Adresse nouvelle à remonter */ result = g_code_buffer_append_new_line_fixme(buffer); g_buffer_line_append_text(result, BLC_COMMENTS, "; ", 2, RTT_COMMENT, NULL); if (length > 0) g_buffer_line_append_text(result, BLC_COMMENTS, text, length, RTT_COMMENT, NULL); return result; } /****************************************************************************** * * * Paramètres : output = encadrant de l'impression en langage de prog. * * line = tampon de sortie à disposition. * * sign = méthode de comparaison à imprimer. * * * * Description : Imprime dans un tampon donné une méthode de comparaison. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_asm_output_write_comp_sign(GAsmOutput *output, GBufferLine *line, CompSignType sign) { g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, " ", 1, RTT_RAW, NULL); switch (sign) { case CST_EQ: g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, "==", 2, RTT_SIGNS, NULL); break; case CST_NE: g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, "!=", 2, RTT_SIGNS, NULL); break; case CST_LT: g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, "<", 1, RTT_SIGNS, NULL); break; case CST_GE: g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, ">=", 2, RTT_SIGNS, NULL); break; case CST_GT: g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, ">", 1, RTT_SIGNS, NULL); break; case CST_LE: g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, "<=", 2, RTT_SIGNS, NULL); break; default: g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, "?", 1, RTT_SIGNS, NULL); break; } g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, " ", 1, RTT_RAW, NULL); } /****************************************************************************** * * * Paramètres : output = encadrant de l'impression en langage de prog. * * buffer = tampon de sortie à disposition. * * * * Description : Débute la documentation d'une routine. * * * * Retour : Ligne nouvellement créée. * * * * Remarques : - * * * ******************************************************************************/ static GBufferLine *g_asm_output_start_routine_info(const GAsmOutput *output, GCodeBuffer *buffer) { GBufferLine *result; /* Adresse nouvelle à remonter */ result = g_code_buffer_append_new_line_fixme(buffer); g_buffer_line_append_text(result, BLC_ASSEMBLY_HEAD, "; ", 2, RTT_COMMENT, NULL); return result; } /****************************************************************************** * * * Paramètres : output = encadrant de l'impression en langage de prog. * * buffer = tampon de sortie à disposition. * * ret = type de retour de la routine traitée. * * * * Description : Débute la définition d'une routine. * * * * Retour : Ligne nouvellement créée. * * * * Remarques : - * * * ******************************************************************************/ static GBufferLine *g_asm_output_start_routine_prototype(GAsmOutput *output, GCodeBuffer *buffer, const GDataType *ret) { GBufferLine *result; /* Adresse nouvelle à remonter */ result = g_code_buffer_append_new_line_fixme(buffer); /* TODO */ g_buffer_line_append_text(result, BLC_ASSEMBLY_HEAD, "XXX", 3, RTT_COMMENT, NULL); return result; } /****************************************************************************** * * * Paramètres : output = encadrant de l'impression en langage de prog. * * buffer = tampon de sortie à disposition. * * line = ligne contenant le prototype de la routine traitée. * * * * Description : Termine la définition d'une routine. * * * * Retour : - * * * * Remarques : - * * * ******************************************************************************/ static void g_asm_output_end_routine_prototype(GAsmOutput *output, GCodeBuffer *buffer, GBufferLine *line) { g_buffer_line_append_text(line, BLC_ASSEMBLY_HEAD, ";", 1, RTT_COMMENT, NULL); }