summaryrefslogtreecommitdiff
path: root/tools/d2c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-06-14 10:35:16 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-06-14 10:35:16 (GMT)
commit4a2f5c39a29bdb4f626bfdb109753ca106a71a33 (patch)
tree9e16d13c063ebd861e9d6c48f940cb2bc62554d3 /tools/d2c
parent04d108111fe7ddd01713b4ca22f8d96961ec2486 (diff)
Handled properly the sign extension when extending values.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@539 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'tools/d2c')
-rw-r--r--tools/d2c/args.c92
-rw-r--r--tools/d2c/args.h6
-rw-r--r--tools/d2c/d2c_gram.y4
-rw-r--r--tools/d2c/d2c_tok.l40
4 files changed, 95 insertions, 47 deletions
diff --git a/tools/d2c/args.c b/tools/d2c/args.c
index 1a2c287..f933160 100644
--- a/tools/d2c/args.c
+++ b/tools/d2c/args.c
@@ -34,25 +34,13 @@
-/*
-#include <assert.h>
-#include <ctype.h>
-
-#include <regex.h>
-#include <stdbool.h>
-#include <sys/param.h>
-
-
-*/
-
-
-
-
/* Types d'expressions représentés */
typedef enum _ConvExprType
{
CET_NAME, /* Désignation de variable */
CET_NUMBER, /* Valeur codée en dur */
+ CET_BINVAL, /* Valeur binaire bxxx */
+ CET_HEXVAL, /* Valeur sous forme hexa. */
CET_COMPOSED, /* Agrégat de champs divers */
CET_UNARY, /* Opération unaire */
CET_BINARY, /* Opération binaire */
@@ -83,6 +71,12 @@ struct _arg_expr_t
/* CET_NUMBER */
unsigned long number; /* Valeur durablement définie */
+ /* CET_BINVAL */
+ char *binval; /* Valeur sous forme bxxx */
+
+ /* CET_HEXVAL */
+ char *hexval; /* Valeur sous forme 0xxxx */
+
/* CET_COMPOSED */
struct
{
@@ -199,6 +193,60 @@ arg_expr_t *build_arg_expr_from_number(unsigned long number)
/******************************************************************************
* *
+* Paramètres : binval = valeur binaire à 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_binval(char *binval)
+{
+ arg_expr_t *result; /* Structure à retourner */
+
+ result = (arg_expr_t *)calloc(1, sizeof(arg_expr_t));
+
+ result->type = CET_BINVAL;
+
+ result->binval = binval;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* 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_hexval(char *hexval)
+{
+ arg_expr_t *result; /* Structure à retourner */
+
+ result = (arg_expr_t *)calloc(1, sizeof(arg_expr_t));
+
+ result->type = CET_HEXVAL;
+
+ result->hexval = hexval;
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : item1 = premier élément à agréger. *
* item2 = second élément à agréger. *
* *
@@ -338,6 +386,14 @@ void delete_arg_expr(arg_expr_t *expr)
free(expr->name);
break;
+ case CET_BINVAL:
+ free(expr->binval);
+ break;
+
+ case CET_HEXVAL:
+ free(expr->hexval);
+ break;
+
case CET_COMPOSED:
for (i = 0; i < expr->comp_count; i++)
free(expr->comp_items[i]);
@@ -856,6 +912,14 @@ bool define_arg_expr(const arg_expr_t *expr, int fd, const coding_bits *bits, co
dprintf(fd, "%lu", expr->number);
break;
+ case CET_BINVAL:
+ dprintf(fd, "b%s", expr->binval);
+ break;
+
+ case CET_HEXVAL:
+ dprintf(fd, "0x%s", expr->hexval);
+ break;
+
case CET_COMPOSED:
result = compute_arg_expr_size(expr, bits, list, &max_size);
diff --git a/tools/d2c/args.h b/tools/d2c/args.h
index d5855f4..b9f210b 100644
--- a/tools/d2c/args.h
+++ b/tools/d2c/args.h
@@ -67,6 +67,12 @@ arg_expr_t *build_arg_expr_from_name(char *);
/* Conserve une valeur en tant qu'expression de conversion. */
arg_expr_t *build_arg_expr_from_number(unsigned long );
+/* Conserve une valeur en tant qu'expression de conversion. */
+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 *);
+
/* Construit une base d'expression de conversion composée. */
arg_expr_t *build_composed_arg_expr(char *, char *);
diff --git a/tools/d2c/d2c_gram.y b/tools/d2c/d2c_gram.y
index 5d83930..9827b05 100644
--- a/tools/d2c/d2c_gram.y
+++ b/tools/d2c/d2c_gram.y
@@ -241,10 +241,12 @@ arg_list : arg_expr { $$ = build_arg_list($1); }
arg_expr : NAME { $$ = build_arg_expr_from_name($1); }
| NUMBER { $$ = build_arg_expr_from_number($1); }
+ | BINVAL { $$ = build_arg_expr_from_binval($1); }
+ | HEXVAL { $$ = build_arg_expr_from_hexval($1); }
| arg_composed { $$ = $1; }
| OP arg_expr CP { $$ = $2; }
| arg_expr_un_op arg_expr { $$ = build_unary_arg_expr($2, $1); }
- | OP arg_expr arg_expr_bin_op arg_expr CP { $$ = build_binary_arg_expr($2, $4, $3); }
+ | arg_expr arg_expr_bin_op arg_expr { $$ = build_binary_arg_expr($1, $3, $2); }
arg_expr_un_op : NOT { $$ = CUO_NOT; }
diff --git a/tools/d2c/d2c_tok.l b/tools/d2c/d2c_tok.l
index 08562ce..300508d 100644
--- a/tools/d2c/d2c_tok.l
+++ b/tools/d2c/d2c_tok.l
@@ -33,9 +33,9 @@ void free_flex_memory(void) ;
%x syntax syntax_name syntax_int syntax_ext
-%x conv_begin conv_content conv_arg conv_arg_binval
+%x conv_begin conv_content
-%x arg arg_binval
+%x arg arg_binval arg_hexval
%x hooks_begin hooks_content
@@ -130,12 +130,12 @@ void free_flex_memory(void) ;
}
}
<conv_content>"=" { return EQ; }
-<conv_content>"(" { BEGIN(conv_arg); return OP; }
+<conv_content>"(" { yy_push_state(arg); return OP; }
-<conv_arg>[A-Za-z_][A-Za-z0-9_]* {
+<arg>[A-Za-z_][A-Za-z0-9_]* {
if (strcmp(yytext, "NOT") == 0) return NOT;
else if (strcmp(yytext, "AND") == 0) return AND_LOG;
else if (strcmp(yytext, "EOR") == 0) return EOR;
@@ -145,45 +145,21 @@ void free_flex_memory(void) ;
return NAME;
}
}
-<conv_arg>[0-9][0-9]* { d2c_lval.integer = atoi(yytext); return NUMBER; }
-<conv_arg>"'" { BEGIN(conv_arg_binval); }
-<conv_arg_binval>[01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; }
-<conv_arg_binval>"'" { BEGIN(conv_arg); }
-<conv_arg>"," { return COMMA; }
-<conv_arg>":" { return COLON; }
-<conv_arg>[ ]+ { }
-<conv_arg>")" { BEGIN(conv_content); return CP; }
-
-
-
-
-
-
-
-
-
-<arg>[A-Za-z_][A-Za-z0-9_]* {
- if (strcmp(yytext, "NOT") == 0) return NOT;
- else if (strcmp(yytext, "AND") == 0) return AND_LOG;
- else if (strcmp(yytext, "EOR") == 0) return EOR;
- else
- {
- d2c_lval.string = strdup(yytext);
- return NAME;
- }
- }
<arg>[0-9][0-9]* { d2c_lval.integer = atoi(yytext); return NUMBER; }
<arg>"'" { BEGIN(arg_binval); }
<arg_binval>[01][01]* { d2c_lval.string = strdup(yytext); return BINVAL; }
<arg_binval>"'" { BEGIN(arg); }
+<arg>"0x" { BEGIN(arg_hexval); }
+<arg_hexval>[0-9a-f][0-9a-f]* { d2c_lval.string = strdup(yytext); BEGIN(arg); return HEXVAL; }
<arg>"," { return COMMA; }
<arg>":" { return COLON; }
+<arg>"&" { return AND_LOG; }
<arg>[ ]+ { }
+<arg>"(" { yy_push_state(arg); return OP; }
<arg>")" { yy_pop_state(); return CP; }
-
<encoding_content>"@hooks" { BEGIN(hooks_begin); return HOOKS; }
<hooks_begin>[ ]+ { }
<hooks_begin>"{" { BEGIN(hooks_content); }