diff options
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/d2c/format/grammar.y | 7 | ||||
| -rw-r--r-- | tools/d2c/format/manager.c | 37 | ||||
| -rw-r--r-- | tools/d2c/format/manager.h | 2 | ||||
| -rw-r--r-- | tools/d2c/format/tokens.l | 6 | 
4 files changed, 35 insertions, 17 deletions
| diff --git a/tools/d2c/format/grammar.y b/tools/d2c/format/grammar.y index 062d616..5cae2f8 100644 --- a/tools/d2c/format/grammar.y +++ b/tools/d2c/format/grammar.y @@ -38,7 +38,7 @@ YY_DECL;  } -%token OPS_TYPE +%token OPS_TYPE OR  %type <string> OPS_TYPE @@ -47,7 +47,10 @@ YY_DECL;  %% -type : OPS_TYPE { set_operands_format_type(format, $1); } +types : type +      | type OR types + +type : OPS_TYPE { add_operands_format_type(format, $1); }  %% diff --git a/tools/d2c/format/manager.c b/tools/d2c/format/manager.c index 070b70c..a799af9 100644 --- a/tools/d2c/format/manager.c +++ b/tools/d2c/format/manager.c @@ -34,7 +34,8 @@  /* Mémorisation de la définition d'opérandes */  struct _operands_format  { -    char *type;                             /* Définitions des opérandes   */ +    char **types;                           /* Définitions des opérandes   */ +    size_t count;                           /* Quantité de définitions     */  }; @@ -77,8 +78,13 @@ operands_format *create_operands_format(void)  void delete_operands_format(operands_format *format)  { -    if (format->type != NULL) -        free(format->type); +    size_t i;                               /* Boucle de parcours          */ + +    for (i = 0; i < format->count; i++) +        free(format->types[i]); + +    if (format->types != NULL) +        free(format->types);      free(format); @@ -98,12 +104,11 @@ void delete_operands_format(operands_format *format)  *                                                                             *  ******************************************************************************/ -void set_operands_format_type(operands_format *format, char *type) +void add_operands_format_type(operands_format *format, char *type)  { -    if (format->type != NULL) -        free(format->type); +    format->types = (char **)realloc(format->types, ++format->count * sizeof(char *)); -    format->type = make_string_upper(type); +    format->types[format->count - 1] = make_string_upper(type);  } @@ -126,7 +131,9 @@ void set_operands_format_type(operands_format *format, char *type)  bool define_operands_loading(const operands_format *format, int fd, const char *arch, const char *prefix, bool *exit)  { -    if (format->type == NULL) +    size_t i;                               /* Boucle de parcours          */ + +    if (format->count == 0)      {          fprintf(stderr, "Error: no type defined for operands.\n");          return false; @@ -134,8 +141,18 @@ bool define_operands_loading(const operands_format *format, int fd, const char *      *exit = true; -    dprintf(fd, "\tif (!%s_read_operands(result, format, content, pos, endian, %s%s))\n", -            arch, prefix, format->type); +    dprintf(fd, "\tif (!%s_read_operands(result, format, content, pos, endian, ", arch); + +    for (i = 0; i < format->count; i++) +    { +        if (i > 0) +            dprintf(fd, " | "); + +        dprintf(fd, "%s%s", prefix, format->types[i]); + +    } + +    dprintf(fd, "))\n");      dprintf(fd, "\t\tgoto bad_exit;\n");      dprintf(fd, "\n"); diff --git a/tools/d2c/format/manager.h b/tools/d2c/format/manager.h index 4555710..461e354 100644 --- a/tools/d2c/format/manager.h +++ b/tools/d2c/format/manager.h @@ -40,7 +40,7 @@ operands_format *create_operands_format(void);  void delete_operands_format(operands_format *);  /* Précise le type d'opérandes dont la définition est à charger. */ -void set_operands_format_type(operands_format *, char *); +void add_operands_format_type(operands_format *, char *);  /* Définit le chargement des opérandes prévus par la définition. */  bool define_operands_loading(const operands_format *, int, const char *, const char *, bool *); diff --git a/tools/d2c/format/tokens.l b/tools/d2c/format/tokens.l index 12ca7f0..9dd9301 100644 --- a/tools/d2c/format/tokens.l +++ b/tools/d2c/format/tokens.l @@ -12,15 +12,13 @@  %option yylineno  %option noyy_top_state -%x bsize -  %% -" "                     { } +" "             { }  [A-Za-z0-9_]*   { yylvalp->string = strdup(yytext); return OPS_TYPE; } - +"|"             { return OR; }  %% | 
