diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-04-02 11:58:42 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-04-02 12:39:30 (GMT) |
commit | 1db4ef323b7a76093356ae76268132f3760e1631 (patch) | |
tree | fec36ee0ec1b6b2010b62ca4177edca0e31e2114 /tools/d2c/rules | |
parent | 1bc80837dde03a32b5ab185067f7bd4c499a9850 (diff) |
Rewritten the whole instruction definition format.
Diffstat (limited to 'tools/d2c/rules')
-rw-r--r-- | tools/d2c/rules/Makefile.am | 3 | ||||
-rw-r--r-- | tools/d2c/rules/manager.c | 64 | ||||
-rw-r--r-- | tools/d2c/rules/manager.h | 3 | ||||
-rw-r--r-- | tools/d2c/rules/tokens.l | 13 |
4 files changed, 39 insertions, 44 deletions
diff --git a/tools/d2c/rules/Makefile.am b/tools/d2c/rules/Makefile.am index 81bf7b8..93d3040 100644 --- a/tools/d2c/rules/Makefile.am +++ b/tools/d2c/rules/Makefile.am @@ -26,6 +26,9 @@ libd2crules_la_SOURCES = \ tokens.l \ grammar.y +# _GNU_SOURCE : asprintf +libd2crules_la_CFLAGS = -D_GNU_SOURCE + # Automake fait les choses à moitié CLEANFILES = grammar.h grammar.c grammar.output tokens.c tokens.h diff --git a/tools/d2c/rules/manager.c b/tools/d2c/rules/manager.c index 74be5fc..20f1a2b 100644 --- a/tools/d2c/rules/manager.c +++ b/tools/d2c/rules/manager.c @@ -290,9 +290,6 @@ static bool mark_cond_expr(const cond_expr *expr, const coding_bits *bits, const } - - printf("=== USE '%s' : %d\n", name, status); - if (!status) fprintf(stderr, "Error: nothing defined for the requested variable '%s'.\n", name); @@ -603,16 +600,14 @@ bool mark_decoding_rules(const decoding_rules *rules, const coding_bits *bits, c /****************************************************************************** * * -* Paramètres : rules = ensemble de règles à consulter. * -* top = indique si l'écriture se fait au plus haut niveau. * -* filter = filtre sur les règles à effectivement imprimer. * -* fd = descripteur d'un flux ouvert en écriture. * -* arch = architecture visée par l'opération. * -* subarch = sous-catégorie de cette même architecture. * -* 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] * +* Paramètres : rules = ensemble de règles à consulter. * +* filter = filtre sur les règles à effectivement imprimer. * +* fd = descripteur d'un flux ouvert en écriture. * +* arch = architecture visée par l'opération. * +* bits = gestionnaire des bits d'encodage. * +* list = liste de l'ensemble des fonctions de conversion. * +* tab = décalage éventuel selon l'inclusion. * +* exit = exprime le besoin d'une voie de sortie. [OUT] * * * * Description : Traduit en code les éventuelles règles présentes. * * * @@ -622,7 +617,7 @@ bool mark_decoding_rules(const decoding_rules *rules, const coding_bits *bits, c * * ******************************************************************************/ -bool write_decoding_rules(decoding_rules *rules, bool top, CondActionType filter, int fd, const char *arch, const char *subarch, const coding_bits *bits, const conv_list *list, const pre_processor *pp, bool *exit) +bool write_decoding_rules(decoding_rules *rules, CondActionType filter, int fd, const char *arch, const coding_bits *bits, const conv_list *list, const char *tab, bool *exit) { bool result; /* Bilan à remonter */ size_t i; /* Boucle de parcours */ @@ -642,6 +637,7 @@ bool write_decoding_rules(decoding_rules *rules, bool top, CondActionType filter switch (rule->action.type) { case CAT_CALL: + case CAT_CHECKED_CALL: multi_lines = false; break; @@ -653,10 +649,7 @@ bool write_decoding_rules(decoding_rules *rules, bool top, CondActionType filter if (rule->expr != NULL) { - if (!top) - dprintf(fd, "\t"); - - dprintf(fd, "\tif "); + dprintf(fd, "\t%sif ", tab); result = write_cond_expr(rule->expr, fd, bits, list); if (!result) break; @@ -664,13 +657,7 @@ bool write_decoding_rules(decoding_rules *rules, bool top, CondActionType filter dprintf(fd, "\n"); if (multi_lines) - { - if (!top) - dprintf(fd, "\t"); - - dprintf(fd, "\t{\n"); - - } + dprintf(fd, "\t%s{\n", tab); } @@ -695,37 +682,42 @@ bool write_decoding_rules(decoding_rules *rules, bool top, CondActionType filter case CAT_CALL: + /* callable = find_macro(pp, rule->action.callee); if (callable == NULL) + */ callable = rule->action.callee; if (rule->expr != NULL) - dprintf(fd, "\t"); + dprintf(fd, "\t") +; + dprintf(fd, "%s", tab); - result = call_instr_func(top, callable, rule->action.args, fd, bits, list, pp); + result = call_instr_func(callable, rule->action.args, fd, bits, list); break; case CAT_CHECKED_CALL: + /* callable = find_macro(pp, rule->action.callee); if (callable == NULL) + */ callable = rule->action.callee; if (rule->expr != NULL) dprintf(fd, "\t"); - result = checked_call_instr_func(top, callable, rule->action.args, fd, bits, list, pp); + dprintf(fd, "%s", tab); - if (rule->expr != NULL) - dprintf(fd, "\t"); + result = checked_call_instr_func(callable, rule->action.args, fd, bits, list); - if (!top) + if (rule->expr != NULL) dprintf(fd, "\t"); - dprintf(fd, "\t\tgoto quick_exit;\n"); + dprintf(fd, "\t\t%sgoto bad_exit;\n", tab); *exit = true; break; @@ -733,13 +725,7 @@ bool write_decoding_rules(decoding_rules *rules, bool top, CondActionType filter } if (rule->expr != NULL && multi_lines) - { - if (!top) - dprintf(fd, "\t"); - - dprintf(fd, "\t}\n"); - - } + dprintf(fd, "\t%s}\n", tab); dprintf(fd, "\n"); diff --git a/tools/d2c/rules/manager.h b/tools/d2c/rules/manager.h index 7f8ef11..88d1d46 100644 --- a/tools/d2c/rules/manager.h +++ b/tools/d2c/rules/manager.h @@ -25,7 +25,6 @@ #define _TOOLS_D2C_RULES_MANAGER_H -#include "../pproc.h" #include "../args/manager.h" #include "../bits/manager.h" #include "../conv/manager.h" @@ -119,7 +118,7 @@ void register_conditional_rule(decoding_rules *, cond_expr *, const rule_action bool mark_decoding_rules(const decoding_rules *, const coding_bits *, const conv_list *); /* Traduit en code les éventuelles règles présentes. */ -bool write_decoding_rules(decoding_rules *, bool, CondActionType, int, const char *, const char *, const coding_bits *, const conv_list *, const pre_processor *, bool *); +bool write_decoding_rules(decoding_rules *, CondActionType, int, const char *, const coding_bits *, const conv_list *, const char *, bool *); diff --git a/tools/d2c/rules/tokens.l b/tools/d2c/rules/tokens.l index 36d6c4a..6b14a85 100644 --- a/tools/d2c/rules/tokens.l +++ b/tools/d2c/rules/tokens.l @@ -23,7 +23,7 @@ %% -\/\/[^\n]+ { printf("SKIP '%s'\n", yytext); } +\/\/[^\n]+ { } "if" { yy_push_state(cond); return IF; } <cond>[ ]+ { } @@ -41,17 +41,24 @@ <cond>";" { yy_pop_state(); return THEN; } -[ ] { } +[ \t\n] { } "see " { yy_push_state(raw_line); return SEE; } "unpredictable" { return UNPREDICTABLE; } "call" { yy_push_state(raw_line); return CALL; } -"chk_call" { yy_push_state(raw_line); return CHK_CALL; } +"check" { yy_push_state(raw_line); return CHK_CALL; } <raw_line>[^\n]+ { yylvalp->cstring = yytext; return RAW_LINE; } <raw_line>"\n" { yy_pop_state(); } +. { + char *msg; + asprintf(&msg, "Unhandled token in d2c rules block: '%s'", yytext); + YY_FATAL_ERROR(msg); + free(msg); + } + %% |