summaryrefslogtreecommitdiff
path: root/tools/d2c/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'tools/d2c/syntax')
-rw-r--r--tools/d2c/syntax/Makefile.am34
-rw-r--r--tools/d2c/syntax/decl.h37
-rw-r--r--tools/d2c/syntax/grammar.y109
-rw-r--r--tools/d2c/syntax/manager.c420
-rw-r--r--tools/d2c/syntax/manager.h73
-rw-r--r--tools/d2c/syntax/tokens.l39
6 files changed, 0 insertions, 712 deletions
diff --git a/tools/d2c/syntax/Makefile.am b/tools/d2c/syntax/Makefile.am
deleted file mode 100644
index 7529978..0000000
--- a/tools/d2c/syntax/Makefile.am
+++ /dev/null
@@ -1,34 +0,0 @@
-
-BUILT_SOURCES = grammar.h
-
-
-# On évite d'utiliser les variables personnalisées de type *_la_[YL]FLAGS
-# afin de conserver des noms de fichiers simples, ie sans le nom de la
-# bibliothèque de sortie en préfixe.
-
-AM_YFLAGS = -v -d -p syntax_
-
-AM_LFLAGS = -P syntax_ -o lex.yy.c --header-file=tokens.h \
- -Dyyget_lineno=syntax_get_lineno \
- -Dyy_scan_string=syntax__scan_string \
- -Dyy_delete_buffer=syntax__delete_buffer
-
-AM_CFLAGS = $(DEBUG_CFLAGS) $(WARNING_FLAGS)
-
-
-noinst_LTLIBRARIES = libd2csyntax.la
-
-.NOTPARALLEL: $(noinst_LTLIBRARIES)
-
-libd2csyntax_la_SOURCES = \
- decl.h \
- manager.h manager.c \
- tokens.l \
- grammar.y
-
-
-# Automake fait les choses à moitié
-CLEANFILES = grammar.h grammar.c grammar.output tokens.c tokens.h
-
-# Pareil : de tous les fichiers générés, seule la sortie de Flex saute pour les distributions !
-EXTRA_DIST = tokens.h
diff --git a/tools/d2c/syntax/decl.h b/tools/d2c/syntax/decl.h
deleted file mode 100644
index 300ab80..0000000
--- a/tools/d2c/syntax/decl.h
+++ /dev/null
@@ -1,37 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * decl.h - déclarations de prototypes utiles
- *
- * Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef _TOOLS_D2C_SYNTAX_DECL_H
-#define _TOOLS_D2C_SYNTAX_DECL_H
-
-
-#include "manager.h"
-
-
-
-/* Interprête des données liées à une définition de syntaxe. */
-bool load_syntax_from_raw_line(asm_syntax *, const char *);
-
-
-
-#endif /* _TOOLS_D2C_SYNTAX_DECL_H */
diff --git a/tools/d2c/syntax/grammar.y b/tools/d2c/syntax/grammar.y
deleted file mode 100644
index 3952b9a..0000000
--- a/tools/d2c/syntax/grammar.y
+++ /dev/null
@@ -1,109 +0,0 @@
-
-%{
-
-#include "tokens.h"
-
-
-/* Affiche un message d'erreur suite à l'analyse en échec. */
-static int yyerror(asm_syntax *, char *);
-
-%}
-
-
-%code requires {
-
-#include "decl.h"
-
-}
-
-
-%union {
-
- char *string; /* Chaîne de caractères */
-
-}
-
-
-%define api.pure full
-
-%parse-param { asm_syntax *syntax }
-
-%code provides {
-
-#define YY_DECL \
- int syntax_lex(YYSTYPE *yylvalp)
-
-YY_DECL;
-
-}
-
-
-%token OPERAND_NAME OPERAND_INTERNAL OPERAND_VISIBLE
-
-%type <string> OPERAND_NAME OPERAND_INTERNAL OPERAND_VISIBLE
-
-
-%%
-
-
-operands : /* empty */
- | operands OPERAND_NAME { register_syntax_item(syntax, $2, SIT_KEYWORD); }
- | operands OPERAND_INTERNAL { register_syntax_item(syntax, $2, SIT_INT_OPERAND); }
- | operands OPERAND_VISIBLE { register_syntax_item(syntax, $2, SIT_EXT_OPERAND); }
-
-
-%%
-
-
-/******************************************************************************
-* *
-* Paramètres : syntax = structure impliquée dans le processus. *
-* msg = message d'erreur. *
-* *
-* Description : Affiche un message d'erreur suite à l'analyse en échec. *
-* *
-* Retour : 0 *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-static int yyerror(asm_syntax *syntax, char *msg)
-{
- printf("syntax yyerror line %d: %s\n", yyget_lineno(), msg);
-
- return 0;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : syntax = structure à constituer à partir de données lues. *
-* raw = données brutes à analyser. *
-* *
-* Description : Interprête des données liées à une définition de syntaxe. *
-* *
-* Retour : true si l'opération s'est bien déroulée, false sinon. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool load_syntax_from_raw_line(asm_syntax *syntax, const char *raw)
-{
- bool result; /* Bilan à faire remonter */
- YY_BUFFER_STATE state; /* Support d'analyse */
- int status; /* Bilan de l'analyse */
-
- state = yy_scan_string(raw);
-
- status = yyparse(syntax);
-
- result = (status == 0);
-
- yy_delete_buffer(state);
-
- return result;
-
-}
diff --git a/tools/d2c/syntax/manager.c b/tools/d2c/syntax/manager.c
deleted file mode 100644
index 6857e9a..0000000
--- a/tools/d2c/syntax/manager.c
+++ /dev/null
@@ -1,420 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * manager.c - prise en compte d'une syntaxe du langage d'assemblage
- *
- * Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>.
- */
-
-
-#include "manager.h"
-
-
-#include <malloc.h>
-#include <string.h>
-
-
-#include "../helpers.h"
-
-
-
-/* Propriétés particulières pour les opérandes */
-typedef enum _SyntaxItemFlags
-{
- SIF_NONE = (0 << 0), /* Aucune propriété */
- SIF_DECIMAL = (1 << 0), /* Affichage en décimal */
- SIF_OPTIONAL = (1 << 1) /* Absence tolérée */
-
-} SyntaxItemFlags;
-
-/* Elément défini dans une syntaxe */
-typedef struct _syntax_item
-{
- char *name; /* Désignation humaine */
- SyntaxItemType impact; /* Portée de l'élément */
- SyntaxItemFlags flags; /* Propriétés supplémentaires */
-
-} syntax_item;
-
-/* Syntaxe d'une ligne d'assembleur */
-struct _asm_syntax
-{
- syntax_item *items; /* Eléments de la syntaxe */
- size_t items_count; /* Nombre de ces éléments */
-
-};
-
-
-
-/******************************************************************************
-* *
-* Paramètres : - *
-* *
-* Description : Crée un nouvel indicateur pour l'écriture d'une instruction. *
-* *
-* Retour : Nouvelle structure prête à emploi. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-asm_syntax *create_asm_syntax(void)
-{
- asm_syntax *result; /* Définition vierge à renvoyer*/
-
- result = (asm_syntax *)calloc(1, sizeof(asm_syntax));
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : syntax = gestionnaire d'un ensemble d'éléments de syntaxe. *
-* *
-* Description : Supprime de la mémoire un indicateur d'écriture ASM. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void delete_asm_syntax(asm_syntax *syntax)
-{
- size_t i; /* Boucle de parcours */
-
- for (i = 0; i < syntax->items_count; i++)
- free(syntax->items[i].name);
-
- if (syntax->items != NULL)
- free(syntax->items);
-
- free(syntax);
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : syntax = gestionnaire d'un ensemble d'éléments de syntaxe. *
-* name = désignation de l'opérande dans la spécification. *
-* impact = précise la portée effective de l'opérande *
-* *
-* Description : Enregistre la présence d'un nouvel opérande dans la syntaxe. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void register_syntax_item(asm_syntax *syntax, char *name, SyntaxItemType impact)
-{
- syntax_item *item; /* Nouvelle prise en compte */
- size_t len; /* Taille du nom fourni */
-
- syntax->items = (syntax_item *)realloc(syntax->items, ++syntax->items_count * sizeof(syntax_item));
-
- item = &syntax->items[syntax->items_count - 1];
-
- /* Récupération des drapeaux */
-
- item->flags = SIF_NONE;
-
- for (len = strlen(name); len > 0; len--)
- switch (name[0])
- {
- case '#':
- item->flags |= SIF_DECIMAL;
- memmove(name, name + 1, len);
- break;
-
- case '?':
- item->flags |= SIF_OPTIONAL;
- memmove(name, name + 1, len);
- break;
-
- default:
- len = 1;
- break;
-
- }
-
- if (impact == SIT_KEYWORD)
- item->name = name;
- else
- item->name = make_string_lower(name);
-
- item->impact = impact;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : syntax = gestionnaire d'un ensemble d'éléments de syntaxe. *
-* bits = gestionnaire des bits d'encodage. *
-* list = liste de l'ensemble des fonctions de conversion. *
-* *
-* Description : Marque les champs de bits effectivement utilisés. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool mark_syntax_items(const asm_syntax *syntax, const coding_bits *bits, const conv_list *list)
-{
- bool result; /* Bilan à retourner */
- size_t i; /* Boucle de parcours */
- syntax_item *item; /* Lien vers un opérande */
- conv_func *func; /* Fonction de conversion */
-
- result = true;
-
- for (i = 0; i < syntax->items_count && result; i++)
- {
- item = &syntax->items[i];
- if (item->impact == SIT_KEYWORD) continue;
-
- func = find_named_conv_in_list(list, item->name);
- if (func == NULL)
- {
- fprintf(stderr, "Error: expected conversion for '%s'.\n", item->name);
- result = false;
- }
-
- result = mark_conv_func(func, false, bits, list);
-
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : syntax = gestionnaire d'un ensemble d'éléments de syntaxe. *
-* fd = descripteur d'un flux ouvert en écriture. *
-* bits = gestionnaire des bits d'encodage. *
-* list = liste de l'ensemble des fonctions de conversion. *
-* wide = taille des mots décodés. *
-* *
-* Description : Déclare les variables C associées aux opérandes de syntaxe. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool declare_syntax_items(const asm_syntax *syntax, int fd, const coding_bits *bits, const conv_list *list, unsigned int wide)
-{
- bool result; /* Bilan à retourner */
- bool has_operand; /* Présence d'un opérande */
- bool has_immediate; /* Présence d'une conversion */
- size_t i; /* Boucle de parcours */
- syntax_item *item; /* Lien vers un opérande */
-
- result = true;
-
- has_operand = false;
- has_immediate = false;
-
- for (i = 0; i < syntax->items_count && result; i++)
- {
- item = &syntax->items[i];
- if (item->impact == SIT_KEYWORD) continue;
-
- has_operand |= (item->impact == SIT_EXT_OPERAND);
-
- if (has_operand)
- has_immediate = (item->flags & SIF_DECIMAL);
-
- }
-
- if (has_operand)
- dprintf(fd, "\t\tGArchOperand *op;\n");
-
- if (has_immediate)
- dprintf(fd, "\t\tGImmOperand *imm;\n");
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : syntax = gestionnaire d'un ensemble d'éléments de syntaxe. *
-* *
-* Description : Fournit si elle existe un nom nouveau pour une instruction. *
-* *
-* Retour : Eventuelle chaîne de caractères trouvée ou NULL. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-const char *get_new_keyword_from_syntax_items(const asm_syntax *syntax)
-{
- const char *result; /* Nom éventuel à renvoyer */
-
- result = NULL;
-
- if (syntax->items_count > 0
- && syntax->items[0].impact == SIT_KEYWORD)
- {
- result = syntax->items[0].name;
- }
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : syntax = gestionnaire d'un ensemble d'éléments de syntaxe. *
-* fd = descripteur d'un flux ouvert en écriture. *
-* arch = architecture visée par l'opération globale. *
-* bits = gestionnaire des bits d'encodage. *
-* list = liste de l'ensemble des fonctions de conversion. *
-* pp = pré-processeur pour les échanges de chaînes. *
-* exit = exprime le besoin d'une voie de sortie. [OUT] *
-* *
-* Description : Définit les variables C associées aux opérandes de syntaxe. *
-* *
-* Retour : Bilan de l'opération. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-bool define_syntax_items(const asm_syntax *syntax, int fd, const char *arch, const coding_bits *bits, const conv_list *list, const pre_processor *pp, bool *exit)
-{
- bool result; /* Bilan à retourner */
- size_t i; /* Boucle de parcours */
- syntax_item *item; /* Lien vers un opérande */
- conv_func *func; /* Fonction de conversion */
- bool internal; /* Usage interne ou non ? */
-
- result = true;
-
- for (i = 0; i < syntax->items_count && result; i++)
- {
- item = &syntax->items[i];
-
- switch (item->impact)
- {
- case SIT_KEYWORD:
-
- /**
- * TODO : à faire évoluer vers extend...
- */
- //_exit(123);
-
- // rev_A88146
- /*
- if (i > 0)
- dprintf(fd, "\t\tg_arch_instruction_append_suffix(instr, \"%s\");\n", item->name);
- else
- continue;
- */
-
- break;
-
- case SIT_INT_OPERAND: // A supprimer
- case SIT_EXT_OPERAND:
-
- internal = (item->impact == SIT_INT_OPERAND);
-
- func = find_named_conv_in_list(list, item->name);
- if (func == NULL)
- {
- fprintf(stderr, "Error: expected conversion for '%s'.\n", item->name);
- result = false;
- }
-
- /* Appel proprement dit */
-
- if (is_conv_func_already_defined(func))
- {
- dprintf(fd, "\t\top = val_%s;\n", item->name);
-
- dprintf(fd, "\n");
-
- if (item->flags & SIF_DECIMAL)
- {
- dprintf(fd, "\t\timm = G_IMM_OPERAND(op)\n");
- dprintf(fd, "\t\tg_imm_operand_set_default_display(&imm, IOD_DEC, NULL);\n");
- dprintf(fd, "\t\timm = G_IMM_OPERAND(op)\n");
- }
-
- dprintf(fd, "\t\tg_arch_instruction_attach_extra_operand(instr, op);\n");
-
- }
-
- else
- {
- result &= define_conv_func(func, true, internal, fd, arch, bits, list, pp, exit);
- if (!result) break;
-
- /* Raccordement : propriété ou opérande ? */
-
- if (internal)
- {
- dprintf(fd, "\t\t\tgoto bad_exit;\n");
- *exit = true;
- }
-
- else
- {
- dprintf(fd, "\t\tif (op == NULL) goto bad_exit;\n");
- *exit = true;
-
- dprintf(fd, "\n");
-
- if (item->flags & SIF_DECIMAL)
- {
- dprintf(fd, "\t\timm = G_IMM_OPERAND(op)\n");
- dprintf(fd, "\t\tg_imm_operand_set_default_display(&imm, IOD_DEC, NULL);\n");
- dprintf(fd, "\t\timm = G_IMM_OPERAND(op)\n");
- }
-
- dprintf(fd, "\t\tg_arch_instruction_attach_extra_operand(instr, op);\n");
-
- }
-
- }
-
- *exit = true;
- break;
-
- }
-
- dprintf(fd, "\n");
-
- }
-
- return result;
-
-}
diff --git a/tools/d2c/syntax/manager.h b/tools/d2c/syntax/manager.h
deleted file mode 100644
index 9cdaa8b..0000000
--- a/tools/d2c/syntax/manager.h
+++ /dev/null
@@ -1,73 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * manager.h - prototypes pour la prise en compte d'une syntaxe du langage d'assemblage
- *
- * Copyright (C) 2016-2017 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 <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef _TOOLS_D2C_SYNTAX_MANAGER_H
-#define _TOOLS_D2C_SYNTAX_MANAGER_H
-
-
-#include <stdbool.h>
-
-
-#include "../pproc.h"
-#include "../bits/manager.h"
-#include "../conv/manager.h"
-
-
-
-/* Type d'éléments de syntaxe */
-typedef enum _SyntaxItemType
-{
- SIT_KEYWORD, /* Elément de l'instruction */
- SIT_INT_OPERAND, /* Propriété d'architecture */
- SIT_EXT_OPERAND /* Opérande généraliste */
-
-} SyntaxItemType;
-
-/* Syntaxe d'une ligne d'assembleur */
-typedef struct _asm_syntax asm_syntax;
-
-
-/* Crée un nouvel indicateur pour l'écriture d'une instruction. */
-asm_syntax *create_asm_syntax(void);
-
-/* Supprime de la mémoire un indicateur d'écriture ASM. */
-void delete_asm_syntax(asm_syntax *);
-
-/* Enregistre la présence d'un nouvel opérande dans la syntaxe. */
-void register_syntax_item(asm_syntax *, char *, SyntaxItemType);
-
-/* Marque les champs de bits effectivement utilisés. */
-bool mark_syntax_items(const asm_syntax *, const coding_bits *, const conv_list *);
-
-/* Déclare les variables C associées aux opérandes de syntaxe. */
-bool declare_syntax_items(const asm_syntax *, int, const coding_bits *, const conv_list *, unsigned int);
-
-/* Fournit si elle existe un nom nouveau pour une instruction. */
-const char *get_new_keyword_from_syntax_items(const asm_syntax *);
-
-/* Définit les variables C associées aux opérandes de syntaxe. */
-bool define_syntax_items(const asm_syntax *, int, const char *, const coding_bits *, const conv_list *, const pre_processor *, bool *);
-
-
-
-#endif /* _TOOLS_D2C_SYNTAX_MANAGER_H */
diff --git a/tools/d2c/syntax/tokens.l b/tools/d2c/syntax/tokens.l
deleted file mode 100644
index ab1b0f3..0000000
--- a/tools/d2c/syntax/tokens.l
+++ /dev/null
@@ -1,39 +0,0 @@
-
-%top {
-
-#include "grammar.h"
-
-}
-
-
-%option noyywrap
-%option nounput
-%option noinput
-%option yylineno
-%option stack
-%option noyy_top_state
-
-%x named
-%x internal
-%x visible
-
-
-%%
-
-
-" " { }
-
-"\"" { yy_push_state(named); }
-<named>[^ \"]+ { yylvalp->string = strdup(yytext); return OPERAND_NAME; }
-<named>"\"" { yy_pop_state(); }
-
-"{" { yy_push_state(internal); }
-<internal>[^ }]+ { yylvalp->string = strdup(yytext); return OPERAND_INTERNAL; }
-<internal>"}" { yy_pop_state(); }
-
-"<" { yy_push_state (visible); }
-<visible>[^ >]+ { yylvalp->string = strdup(yytext); return OPERAND_VISIBLE; }
-<visible>">" { yy_pop_state(); }
-
-
-%%