summaryrefslogtreecommitdiff
path: root/tools/d2c/conv/manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/d2c/conv/manager.c')
-rw-r--r--tools/d2c/conv/manager.c154
1 files changed, 144 insertions, 10 deletions
diff --git a/tools/d2c/conv/manager.c b/tools/d2c/conv/manager.c
index fca9ce0..09368ce 100644
--- a/tools/d2c/conv/manager.c
+++ b/tools/d2c/conv/manager.c
@@ -42,6 +42,8 @@
/* Fonction de conversion */
struct _conv_func
{
+ bool used; /* Conversion utilisée ? */
+ bool intermediate; /* Variable intermédiaire ? */
bool declared; /* Expression déjà déclarée ? */
bool defined; /* Expression déjà définie ? */
@@ -241,9 +243,10 @@ bool compute_conv_func_size(const conv_func *func, const coding_bits *bits, cons
/******************************************************************************
* *
-* Paramètres : func = fonction de conversion à manipuler. *
-* bits = gestionnaire des bits d'encodage. *
-* list = liste de l'ensemble des fonctions de conversion. *
+* Paramètres : func = fonction de conversion à manipuler. *
+* inter = note un résultat de conversion comme intermédiaire. *
+* bits = gestionnaire des bits d'encodage. *
+* list = liste de l'ensemble des fonctions de conversion. *
* *
* Description : Marque les champs utilisés par une fonction de conversion. *
* *
@@ -253,10 +256,13 @@ bool compute_conv_func_size(const conv_func *func, const coding_bits *bits, cons
* *
******************************************************************************/
-bool mark_conv_func(conv_func *func, const coding_bits *bits, const conv_list *list)
+bool mark_conv_func(conv_func *func, bool inter, const coding_bits *bits, const conv_list *list)
{
bool result; /* Bilan à remonter */
+ func->used = true;
+ func->intermediate |= inter;
+
if (func->is_expr)
result = ensure_arg_expr_content_fully_marked(func->expr, bits, list);
else
@@ -273,6 +279,7 @@ bool mark_conv_func(conv_func *func, const coding_bits *bits, const conv_list *l
* fd = descripteur d'un flux ouvert en écriture. *
* bits = gestionnaire des bits d'encodage. *
* list = liste de l'ensemble des fonctions de conversion. *
+* pp = pré-processeur pour les échanges de chaînes. *
* wide = taille des mots décodés. *
* *
* Description : Déclare les variables associées à une fonction de conversion.*
@@ -283,18 +290,31 @@ bool mark_conv_func(conv_func *func, const coding_bits *bits, const conv_list *l
* *
******************************************************************************/
-bool declare_conv_func(conv_func *func, int fd, const coding_bits *bits, const conv_list *list, unsigned int wide)
+bool declare_conv_func(conv_func *func, int fd, const coding_bits *bits, const conv_list *list, const pre_processor *pp, unsigned int wide)
{
bool result; /* Bilan à remonter */
+ printf(" -> declaration for '%s': declared ? %d - expr ? %d\n",
+ func->dest, func->declared, func->is_expr);
+
+ assert(func->used);
+
/* Si la fonction a déjà été définie lors d'un précédent besoin... */
if (func->declared) return true;
if (func->is_expr)
- result = ensure_arg_expr_content_fully_declared(func->expr, fd, bits, list, wide);
+ result = ensure_arg_expr_content_fully_declared(func->expr, fd, bits, list, pp, wide);
else
- result = ensure_arg_list_content_fully_declared(func->args, fd, bits, list, wide);
+ result = ensure_arg_list_content_fully_declared(func->args, fd, bits, list, pp, wide);
+
+ if (result && func->intermediate)
+ {
+ if (!func->is_expr && is_operand_producer(pp, func->name))
+ dprintf(fd, "\t\tGArchOperand *val_%s;\n", func->dest);
+ else
+ dprintf(fd, "\t\tuint%u_t val_%s;\n", wide, func->dest);
+ }
func->declared = result;
@@ -305,6 +325,25 @@ bool declare_conv_func(conv_func *func, int fd, const coding_bits *bits, const c
/******************************************************************************
* *
+* Paramètres : func = fonction de conversion à consulter. *
+* *
+* Description : Indique si une conversion a déjà été définie. *
+* *
+* Retour : Etat de la définition. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool is_conv_func_already_defined(const conv_func *func)
+{
+ return func->defined;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : func = fonction de conversion à manipuler. *
* last = précise si la conversion est la dernière. *
* internal = indique le type de manipulation finale. *
@@ -313,6 +352,7 @@ bool declare_conv_func(conv_func *func, int fd, const coding_bits *bits, const c
* 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 associées à une fonction de conversion.*
* *
@@ -322,7 +362,7 @@ bool declare_conv_func(conv_func *func, int fd, const coding_bits *bits, const c
* *
******************************************************************************/
-bool define_conv_func(conv_func *func, bool last, bool internal, int fd, const char *arch, const coding_bits *bits, const conv_list *list, const pre_processor *pp)
+bool define_conv_func(conv_func *func, bool last, bool internal, int fd, const char *arch, const coding_bits *bits, const conv_list *list, const pre_processor *pp, bool *exit)
{
bool result; /* Bilan à remonter */
const char *callable; /* Fonction à appeler */
@@ -331,9 +371,9 @@ bool define_conv_func(conv_func *func, bool last, bool internal, int fd, const c
if (func->defined) return true;
if (func->is_expr)
- result = ensure_arg_expr_content_fully_defined(func->expr, fd, arch, bits, list, pp);
+ result = ensure_arg_expr_content_fully_defined(func->expr, fd, arch, bits, list, pp, exit);
else
- result = ensure_arg_list_content_fully_defined(func->args, fd, arch, bits, list, pp);
+ result = ensure_arg_list_content_fully_defined(func->args, fd, arch, bits, list, pp, exit);
/* Nom de la fonction effectivement appelée */
@@ -396,6 +436,12 @@ bool define_conv_func(conv_func *func, bool last, bool internal, int fd, const c
dprintf(fd, ";\n");
+ if (!func->is_expr && is_operand_producer(pp, func->name))
+ {
+ dprintf(fd, "\t\tif (val_%s == NULL) goto bad_exit;\n", func->dest);
+ *exit = true;
+ }
+
}
func->defined = result;
@@ -516,3 +562,91 @@ conv_func *find_named_conv_in_list(const conv_list *list, const char *name)
return result;
}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste de fonctions de conversion à consulter. *
+* fd = descripteur d'un flux ouvert en écriture. *
+* bits = gestionnaire des bits d'encodage. *
+* pp = pré-processeur pour les échanges de chaînes. *
+* wide = taille des mots décodés. *
+* *
+* Description : Déclare l'ensemble des variables intermédiaires. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool declare_used_intermediate_conversions(const conv_list *list, int fd, const coding_bits *bits, const pre_processor *pp, unsigned int wide)
+{
+ bool result; /* Bilan à remonter */
+ size_t i; /* Boucle de parcours */
+ conv_func *func; /* Conversion à traiter */
+
+ result = true;
+
+ for (i = 0; i < list->func_count && result; i++)
+ {
+ func = list->functions[i];
+
+ if (func->used && func->intermediate)
+ result = declare_conv_func(func, fd, bits, list, pp, wide);
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : list = liste de fonctions de conversion à consulter. *
+* fd = descripteur d'un flux ouvert en écriture. *
+* arch = architecture visée par l'opération globale. *
+* bits = gestionnaire des bits d'encodage. *
+* pp = pré-processeur pour les échanges de chaînes. *
+* exit = exprime le besoin d'une voie de sortie. [OUT] *
+* *
+* Description : Définit l'ensemble des variables intermédiaires. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool define_used_intermediate_conversions(const conv_list *list, int fd, const char *arch, const coding_bits *bits, const pre_processor *pp, bool *exit)
+{
+ bool result; /* Bilan à remonter */
+ bool got_one; /* Suit le nombre d'impressions*/
+ size_t i; /* Boucle de parcours */
+ conv_func *func; /* Conversion à traiter */
+
+ result = true;
+
+ got_one = false;
+
+ for (i = 0; i < list->func_count && result; i++)
+ {
+ func = list->functions[i];
+
+ if (func->used && func->intermediate)
+ {
+ result = define_conv_func(func, false, false, fd, arch, bits, list, pp, exit);
+
+ got_one = true;
+
+ }
+
+ }
+
+ if (got_one)
+ dprintf(fd, "\n");
+
+ return result;
+
+}