diff options
Diffstat (limited to 'tools/d2c/args')
-rw-r--r-- | tools/d2c/args/grammar.y | 18 | ||||
-rw-r--r-- | tools/d2c/args/manager.c | 201 | ||||
-rw-r--r-- | tools/d2c/args/manager.h | 17 | ||||
-rw-r--r-- | tools/d2c/args/tokens.l | 7 |
4 files changed, 215 insertions, 28 deletions
diff --git a/tools/d2c/args/grammar.y b/tools/d2c/args/grammar.y index 6477c47..f44a94b 100644 --- a/tools/d2c/args/grammar.y +++ b/tools/d2c/args/grammar.y @@ -50,18 +50,19 @@ YY_DECL; %token FORCE_EXPR FORCE_CALL ALLOW_ALL %token NAME -%token NUMBER BINVAL HEXVAL +%token NUMBER BINVAL HEXVAL STRING %token COMMA COLON OP CP -%token NOT AND_LOG EOR +%token NOT AND_LOG EOR EQ NE +%token AND_BOOL OR_BOOL %type <string> NAME %type <integer> NUMBER -%type <string> BINVAL HEXVAL +%type <string> BINVAL HEXVAL STRING %type <operand> call %type <args> arg_list -%type <arg> arg_expr arg_composed +%type <arg> arg_expr arg_logical_expr arg_composed %type <un_op> arg_expr_un_op %type <bin_op> arg_expr_bin_op %type <string> arg_field @@ -84,9 +85,13 @@ arg_expr : NAME { $$ = build_arg_expr_from_n | NUMBER { $$ = build_arg_expr_from_number($1); } | BINVAL { $$ = build_arg_expr_from_binval($1); } | HEXVAL { $$ = build_arg_expr_from_hexval($1); } + | STRING { $$ = build_arg_expr_from_string($1); } + | arg_logical_expr { $$ = $1; } | arg_composed { $$ = $1; } | OP arg_expr CP { $$ = $2; } | arg_expr_un_op arg_expr { $$ = build_unary_arg_expr($2, $1); } + | arg_expr EQ arg_expr { $$ = build_conditional_arg_expr($1, $3, true); } + | arg_expr NE arg_expr { $$ = build_conditional_arg_expr($1, $3, false); } | arg_expr arg_expr_bin_op arg_expr { $$ = build_binary_arg_expr($1, $3, $2); } arg_expr_un_op : NOT { $$ = CUO_NOT; } @@ -94,6 +99,11 @@ arg_expr_un_op : NOT { $$ = CUO_NOT; } arg_expr_bin_op : AND_LOG { $$ = CBO_AND; } | EOR { $$ = CBO_EOR; } +arg_logical_expr : arg_expr AND_BOOL arg_expr { $$ = build_logical_arg_expr($1, $3, true); } + | arg_logical_expr AND_BOOL arg_expr { $$ = build_logical_arg_expr($1, $3, true); } + | arg_expr OR_BOOL arg_expr { $$ = build_logical_arg_expr($1, $3, false); } + | arg_logical_expr OR_BOOL arg_expr { $$ = build_logical_arg_expr($1, $3, false); } + arg_composed : arg_field COLON arg_field { $$ = build_composed_arg_expr($1, $3); } | arg_composed COLON arg_field { $$ = extend_composed_arg_expr($1, $3); } diff --git a/tools/d2c/args/manager.c b/tools/d2c/args/manager.c index ce300e6..498dd5c 100644 --- a/tools/d2c/args/manager.c +++ b/tools/d2c/args/manager.c @@ -41,8 +41,11 @@ typedef enum _ConvExprType CET_NUMBER, /* Valeur codée en dur */ CET_BINVAL, /* Valeur binaire bxxx */ CET_HEXVAL, /* Valeur sous forme hexa. */ + CET_STRING, /* Valeur sous forme de chaîne */ + CET_LOGICAL, /* Expression booléenne logique*/ CET_COMPOSED, /* Agrégat de champs divers */ CET_UNARY, /* Opération unaire */ + CET_CONDITIONAL, /* Valeur booléenne */ CET_BINARY, /* Opération binaire */ CET_COUNT @@ -77,6 +80,18 @@ struct _arg_expr_t /* CET_HEXVAL */ char *hexval; /* Valeur sous forme 0xxxx */ + /* CET_STRING */ + char *string; /* Chaîne "..." sans '"' */ + + /* CET_LOGICAL */ + struct + { + arg_expr_t *logical_expr1; /* Expression à traiter */ + arg_expr_t *logical_expr2; /* Expression à traiter */ + bool and_op; /* Type de condition booléenne */ + + }; + /* CET_COMPOSED */ struct { @@ -93,6 +108,15 @@ struct _arg_expr_t }; + /* CET_CONDITIONAL */ + struct + { + arg_expr_t *cond_expr1; /* Expression à traiter */ + arg_expr_t *cond_expr2; /* Expression à traiter */ + bool cond_equal; /* Type de condition booléenne */ + + }; + /* CET_BINARY */ struct { @@ -247,6 +271,64 @@ arg_expr_t *build_arg_expr_from_hexval(char *hexval) /****************************************************************************** * * +* Paramètres : number = valeur hexadécimale à conserver dans sa forme brute.* +* * +* Description : Conserve une valeur en tant qu'expression de conversion. * +* * +* Retour : Nouvelle expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +arg_expr_t *build_arg_expr_from_string(char *string) +{ + arg_expr_t *result; /* Structure à retourner */ + + result = (arg_expr_t *)calloc(1, sizeof(arg_expr_t)); + + result->type = CET_STRING; + + result->string = string; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : expr1 = première expression à utiliser. * +* expr2 = seconde expression à utiliser. * +* and_op = choix de l'opérateur ('&&' ou '||'). * +* * +* Description : Construit une base d'expression booléenne logique. * +* * +* Retour : Nouvelle expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + +arg_expr_t *build_logical_arg_expr(arg_expr_t *expr1, arg_expr_t *expr2, bool and_op) +{ + arg_expr_t *result; /* Structure à retourner */ + + result = (arg_expr_t *)calloc(1, sizeof(arg_expr_t)); + + result->type = CET_LOGICAL; + + result->logical_expr1 = expr1; + result->logical_expr2 = expr2; + result->and_op = and_op; + + return result; + +} + + +/****************************************************************************** +* * * Paramètres : item1 = premier élément à agréger. * * item2 = second élément à agréger. * * * @@ -346,6 +428,37 @@ arg_expr_t *build_unary_arg_expr(arg_expr_t *expr, ConvUnaryOperation op) * * ******************************************************************************/ +arg_expr_t *build_conditional_arg_expr(arg_expr_t *expr1, arg_expr_t *expr2, bool eq) +{ + arg_expr_t *result; /* Structure à retourner */ + + result = (arg_expr_t *)calloc(1, sizeof(arg_expr_t)); + + result->type = CET_CONDITIONAL; + + result->cond_expr1 = expr1; + result->cond_expr2 = expr2; + result->cond_equal = eq; + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : expr1 = première expression à encapsuler. * +* expr2 = seconde expression à encapsuler. * +* op = opération binaire à associer à l'opération. * +* * +* Description : Traduit une opération binaire sur expression de conversion. * +* * +* Retour : Nouvelle expression mise en place. * +* * +* Remarques : - * +* * +******************************************************************************/ + arg_expr_t *build_binary_arg_expr(arg_expr_t *expr1, arg_expr_t *expr2, ConvBinaryOperation op) { arg_expr_t *result; /* Structure à retourner */ @@ -394,6 +507,11 @@ void delete_arg_expr(arg_expr_t *expr) free(expr->hexval); break; + case CET_LOGICAL: + free(expr->logical_expr1); + free(expr->logical_expr2); + break; + case CET_COMPOSED: for (i = 0; i < expr->comp_count; i++) free(expr->comp_items[i]); @@ -543,10 +661,20 @@ static bool visit_arg_expr(arg_expr_t *expr, visit_expr_fc visit, int fd, const switch (expr->type) { + case CET_LOGICAL: + result = visit_arg_expr(expr->logical_expr1, visit, fd, bits, list, data); + result = visit_arg_expr(expr->logical_expr2, visit, fd, bits, list, data); + break; + case CET_UNARY: result = visit_arg_expr(expr->un_expr, visit, fd, bits, list, data); break; + case CET_CONDITIONAL: + result = visit_arg_expr(expr->cond_expr1, visit, fd, bits, list, data); + result = visit_arg_expr(expr->cond_expr2, visit, fd, bits, list, data); + break; + case CET_BINARY: result = visit_arg_expr(expr->bin_expr1, visit, fd, bits, list, data); result = visit_arg_expr(expr->bin_expr2, visit, fd, bits, list, data); @@ -643,7 +771,7 @@ bool ensure_arg_expr_content_fully_marked(arg_expr_t *expr, const coding_bits *b if (field != NULL) mark_raw_bitfield_as_used(field); else /*if (func != NULL) */ - mark_conv_func(func, bts, lst); + mark_conv_func(func, true, bts, lst); printf(" VAR '%s' found (bf=%d fc=%d)\n", name, !!field, !!func); @@ -692,6 +820,7 @@ bool ensure_arg_expr_content_fully_marked(arg_expr_t *expr, const coding_bits *b * 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. * * wide = taille des mots décodés. * * * * Description : S'assure de la déclaration des expressions pre-requises. * @@ -702,9 +831,9 @@ bool ensure_arg_expr_content_fully_marked(arg_expr_t *expr, const coding_bits *b * * ******************************************************************************/ -bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const coding_bits *bits, const conv_list *list, unsigned int wide) +bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const coding_bits *bits, const conv_list *list, const pre_processor *pp, unsigned int wide) { - bool declare_sub_expr(arg_expr_t *sub, int f, const coding_bits *bts, const conv_list *lst, unsigned int *wide) + bool declare_sub_expr(arg_expr_t *sub, int f, const coding_bits *bts, const conv_list *lst, unsigned int *wideptr) { bool result; /* Bilan à retourner */ size_t i; /* Boucle de parcours */ @@ -713,7 +842,7 @@ bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const codi printf(" sub declared ? %d -- type = %d\n", sub->declared, sub->type); if (sub->declared) return true; - bool declare_by_name(int _f, const coding_bits *_bts, const conv_list *_lst, unsigned int _wide, const char *name) + bool declare_by_name(const char *name) { bool found; /* Bilan d'opération à renvoyer*/ conv_func *func; /* Eventuelle fonction liée */ @@ -723,7 +852,7 @@ bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const codi if (found && func != NULL) { printf("========= DECLARE for '%s'\n", name); - found = declare_conv_func(func, _f, _bts, _lst, _wide); + found = declare_conv_func(func, fd, bits, list, pp, wide); printf("========= END DECLARE for '%s'\n", name); /** @@ -733,10 +862,13 @@ bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const codi * car les appels racine servent directement d'arguments. */ + /* if (is_conv_func_expression(func)) - dprintf(_f, "\t\tuint%u_t val_%s; // Ho\n", _wide, name); + dprintf(_f, "\t\tuint%u_t val_%s; // Ho\n", _wide, name); // FIXME else - dprintf(_f, "\t\tGArchOperand *val_%s;;;;;\n", name); + dprintf(_f, "\t\tGArchOperand *val_%s;;;;;\n", name); // FIXME + */ + } @@ -748,7 +880,7 @@ bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const codi switch (sub->type) { case CET_NAME: - /* result = */declare_by_name(f, bits, lst, *wide, sub->name); + /* result = */declare_by_name(sub->name); result = true; break; @@ -756,10 +888,7 @@ bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const codi result = true; for (i = 0; i < sub->comp_count && result; i++) if (!isdigit(sub->comp_items[i][0])) - printf("... trying to declare... '%s'\n", sub->comp_items[i]); - for (i = 0; i < sub->comp_count && result; i++) - if (!isdigit(sub->comp_items[i][0])) - result = declare_by_name(f, bits, lst, *wide, sub->comp_items[i]); + result = declare_by_name(sub->comp_items[i]); break; default: @@ -787,6 +916,7 @@ bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const codi * 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 : S'assure de la définition des expressions pre-requises. * * * @@ -796,7 +926,7 @@ bool ensure_arg_expr_content_fully_declared(arg_expr_t *expr, int fd, const codi * * ******************************************************************************/ -bool ensure_arg_expr_content_fully_defined(arg_expr_t *expr, int fd, const char *arch, const coding_bits *bits, const conv_list *list, const pre_processor *pp) +bool ensure_arg_expr_content_fully_defined(arg_expr_t *expr, int fd, const char *arch, const coding_bits *bits, const conv_list *list, const pre_processor *pp, bool *exit) { typedef struct _def_info { @@ -823,7 +953,7 @@ bool ensure_arg_expr_content_fully_defined(arg_expr_t *expr, int fd, const char found = find_var_by_name(bts, lst, name, NULL, &func); if (found && func != NULL) - found = define_conv_func(func, false, false, _f, _info->arch, _bts, _lst, _info->pp); + found = define_conv_func(func, false, false, _f, _info->arch, _bts, _lst, _info->pp, exit); return found; @@ -920,12 +1050,24 @@ bool define_arg_expr(const arg_expr_t *expr, int fd, const coding_bits *bits, co dprintf(fd, "0x%s", expr->hexval); break; + case CET_STRING: + dprintf(fd, "\"%s\"", expr->string); + break; + + case CET_LOGICAL: + + result = define_arg_expr(expr->logical_expr1, fd, bits, list); + + dprintf(fd, expr->and_op ? " && " : " || "); + + result &= define_arg_expr(expr->logical_expr2, fd, bits, list); + + break; + case CET_COMPOSED: result = compute_arg_expr_size(expr, bits, list, &max_size); - printf("MAX SIZE :: %u\n", max_size); - for (i = 0; i < expr->comp_count && result; i++) { cname = expr->comp_items[i]; @@ -998,6 +1140,23 @@ bool define_arg_expr(const arg_expr_t *expr, int fd, const coding_bits *bits, co break; + case CET_CONDITIONAL: + + dprintf(fd, "("); + + result = define_arg_expr(expr->cond_expr1, fd, bits, list); + + if (expr->cond_equal) + dprintf(fd, " == "); + else + dprintf(fd, " != "); + + result &= define_arg_expr(expr->cond_expr2, fd, bits, list); + + dprintf(fd, ")"); + + break; + case CET_BINARY: dprintf(fd, "("); @@ -1154,6 +1313,7 @@ bool ensure_arg_list_content_fully_marked(arg_list_t *args, const coding_bits *b * 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 : S'assure de la déclaration des expressions pre-requises. * @@ -1164,7 +1324,7 @@ bool ensure_arg_list_content_fully_marked(arg_list_t *args, const coding_bits *b * * ******************************************************************************/ -bool ensure_arg_list_content_fully_declared(arg_list_t *args, int fd, const coding_bits *bits, const conv_list *list, unsigned int wide) +bool ensure_arg_list_content_fully_declared(arg_list_t *args, int fd, const coding_bits *bits, const conv_list *list, const pre_processor *pp, unsigned int wide) { bool result; /* Bilan à remonter */ size_t i; /* Boucle de parcours */ @@ -1172,7 +1332,7 @@ bool ensure_arg_list_content_fully_declared(arg_list_t *args, int fd, const codi result = true; for (i = 0; i < args->count && result; i++) - result = ensure_arg_expr_content_fully_declared(args->items[i], fd, bits, list, wide); + result = ensure_arg_expr_content_fully_declared(args->items[i], fd, bits, list, pp, wide); return result; @@ -1187,6 +1347,7 @@ bool ensure_arg_list_content_fully_declared(arg_list_t *args, int fd, const codi * 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 : S'assure de la définition des expressions pre-requises. * * * @@ -1196,7 +1357,7 @@ bool ensure_arg_list_content_fully_declared(arg_list_t *args, int fd, const codi * * ******************************************************************************/ -bool ensure_arg_list_content_fully_defined(arg_list_t *args, int fd, const char *arch, const coding_bits *bits, const conv_list *list, const pre_processor *pp) +bool ensure_arg_list_content_fully_defined(arg_list_t *args, int fd, const char *arch, const coding_bits *bits, const conv_list *list, const pre_processor *pp, bool *exit) { bool result; /* Bilan à remonter */ size_t i; /* Boucle de parcours */ @@ -1204,7 +1365,7 @@ bool ensure_arg_list_content_fully_defined(arg_list_t *args, int fd, const char result = true; for (i = 0; i < args->count && result; i++) - result = ensure_arg_expr_content_fully_defined(args->items[i], fd, arch, bits, list, pp); + result = ensure_arg_expr_content_fully_defined(args->items[i], fd, arch, bits, list, pp, exit); return result; diff --git a/tools/d2c/args/manager.h b/tools/d2c/args/manager.h index 85fc0a8..111b6db 100644 --- a/tools/d2c/args/manager.h +++ b/tools/d2c/args/manager.h @@ -73,6 +73,12 @@ arg_expr_t *build_arg_expr_from_binval(char *); /* Conserve une valeur en tant qu'expression de conversion. */ arg_expr_t *build_arg_expr_from_hexval(char *); +/* Conserve une valeur en tant qu'expression de conversion. */ +arg_expr_t *build_arg_expr_from_string(char *); + +/* Construit une base d'expression booléenne logique. */ +arg_expr_t *build_logical_arg_expr(arg_expr_t *, arg_expr_t *, bool); + /* Construit une base d'expression de conversion composée. */ arg_expr_t *build_composed_arg_expr(char *, char *); @@ -83,6 +89,9 @@ arg_expr_t *extend_composed_arg_expr(arg_expr_t *, char *); arg_expr_t *build_unary_arg_expr(arg_expr_t *, ConvUnaryOperation); /* Traduit une opération binaire sur expression de conversion. */ +arg_expr_t *build_conditional_arg_expr(arg_expr_t *, arg_expr_t *, bool); + +/* Traduit une opération binaire sur expression de conversion. */ arg_expr_t *build_binary_arg_expr(arg_expr_t *, arg_expr_t *, ConvBinaryOperation); /* Supprime tous les éléments mis en place pour un argument. */ @@ -95,10 +104,10 @@ bool compute_arg_expr_size(const arg_expr_t *, const coding_bits *, const conv_l bool ensure_arg_expr_content_fully_marked(arg_expr_t *, const coding_bits *, const conv_list *); /* S'assure de la déclaration des expressions pre-requises. */ -bool ensure_arg_expr_content_fully_declared(arg_expr_t *, int, const coding_bits *, const conv_list *, unsigned int); +bool ensure_arg_expr_content_fully_declared(arg_expr_t *, int, const coding_bits *, const conv_list *, const pre_processor *, unsigned int); /* S'assure de la définition des expressions pre-requises. */ -bool ensure_arg_expr_content_fully_defined(arg_expr_t *, int, const char *, const coding_bits *, const conv_list *, const pre_processor *); +bool ensure_arg_expr_content_fully_defined(arg_expr_t *, int, const char *, const coding_bits *, const conv_list *, const pre_processor *, bool *); /* Définit une expression utilisée dans une conversion. */ bool define_arg_expr(const arg_expr_t *, int, const coding_bits *, const conv_list *); @@ -125,10 +134,10 @@ arg_list_t *extend_arg_list(arg_list_t *, arg_expr_t *); bool ensure_arg_list_content_fully_marked(arg_list_t *, const coding_bits *, const conv_list *); /* S'assure de la déclaration des expressions pre-requises. */ -bool ensure_arg_list_content_fully_declared(arg_list_t *, int, const coding_bits *, const conv_list *, unsigned int); +bool ensure_arg_list_content_fully_declared(arg_list_t *, int, const coding_bits *, const conv_list *, const pre_processor *, unsigned int); /* S'assure de la définition des expressions pre-requises. */ -bool ensure_arg_list_content_fully_defined(arg_list_t *, int, const char *, const coding_bits *, const conv_list *, const pre_processor *); +bool ensure_arg_list_content_fully_defined(arg_list_t *, int, const char *, const coding_bits *, const conv_list *, const pre_processor *, bool *); /* Définit les variables associées à un appel de fonction. */ bool define_arg_list(const arg_list_t *, int, const coding_bits *, const conv_list *); diff --git a/tools/d2c/args/tokens.l b/tools/d2c/args/tokens.l index 4b1a2a1..2a4ffb2 100644 --- a/tools/d2c/args/tokens.l +++ b/tools/d2c/args/tokens.l @@ -51,12 +51,19 @@ <binval>[01][01]* { yylvalp->string = strdup(yytext); return BINVAL; } <binval>"'" { yy_pop_state(); } +\"[^\"]*\" { yylvalp->string = strndup(yytext + 1, strlen(yytext) - 2); printf("str = '%s'\n", yylvalp->string); return STRING; } + "0x" { yy_push_state(hexval); } <hexval>[0-9a-f][0-9a-f]* { yylvalp->string = strdup(yytext); yy_pop_state(); return HEXVAL; } "," { return COMMA; } ":" { return COLON; } "&" { return AND_LOG; } +"==" { return EQ; } +"!=" { return NE; } + +"&&" { return AND_BOOL; } +"||" { return OR_BOOL; } "(" { yy_push_state(INITIAL); return OP; } ")" { yy_pop_state(); return CP; } |