diff options
Diffstat (limited to 'tools/d2c/bits')
-rw-r--r-- | tools/d2c/bits/Makefile.am | 3 | ||||
-rw-r--r-- | tools/d2c/bits/manager.c | 53 | ||||
-rw-r--r-- | tools/d2c/bits/manager.h | 4 | ||||
-rw-r--r-- | tools/d2c/bits/tokens.l | 6 |
4 files changed, 58 insertions, 8 deletions
diff --git a/tools/d2c/bits/Makefile.am b/tools/d2c/bits/Makefile.am index b1d79b6..0d8beb8 100644 --- a/tools/d2c/bits/Makefile.am +++ b/tools/d2c/bits/Makefile.am @@ -26,6 +26,9 @@ libd2cbits_la_SOURCES = \ tokens.l \ grammar.y +# _GNU_SOURCE : asprintf +libd2cbits_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/bits/manager.c b/tools/d2c/bits/manager.c index 4999680..560bade 100644 --- a/tools/d2c/bits/manager.c +++ b/tools/d2c/bits/manager.c @@ -29,6 +29,7 @@ #include <malloc.h> #include <stdint.h> #include <string.h> +#include <unistd.h> #include "../helpers.h" @@ -114,6 +115,25 @@ void mark_raw_bitfield_as_used(raw_bitfield *field) } +/****************************************************************************** +* * +* Paramètres : field = champ de bits à traiter. * +* fd = descripteur d'un flux ouvert en écriture. * +* * +* Description : Imprime la désignation d'un champ de bits dans du code. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void write_raw_bitfield(const raw_bitfield *field, int fd) +{ + dprintf(fd, "raw_%s", field->name); + +} + @@ -294,13 +314,30 @@ raw_bitfield *find_named_field_in_bits(const coding_bits *bits, const char *name * * ******************************************************************************/ -bool declare_used_bits_fields(const coding_bits *bits, int fd, unsigned int wide) +bool declare_used_bits_fields(const coding_bits *bits, int fd) { + unsigned int wide; /* Taille des mots */ size_t i; /* Boucle de parcours */ + off_t start; /* Point de départ dans le code*/ + off_t end; /* Point d'arrivée dans le code*/ + + wide = count_coded_bits(bits); for (i = 0; i < bits->bf_count; i++) if (bits->fields[i].used) - dprintf(fd, "\t\tuint%u_t raw_%s;\n", wide, bits->fields[i].name); + { + start = lseek(fd, 0, SEEK_CUR); + + dprintf(fd, "\tuint%u_t ", wide); + write_raw_bitfield(&bits->fields[i], fd); + dprintf(fd, ";"); + + end = lseek(fd, 0, SEEK_CUR); + + dprintf(fd, "%*s", 42 - (int)(end - start), "/"); + dprintf(fd, "* Champ brut à décoder */\n"); + + } return true; @@ -325,22 +362,22 @@ bool check_bits_correctness(const coding_bits *bits, int fd) switch (bits->curpos) { case 8: - dprintf(fd, "\t\tif ((raw & 0x%" PRIx8 ") != 0x%" PRIx8 ") return NULL;\n", + dprintf(fd, "\tif ((raw & 0x%" PRIx8 ") != 0x%" PRIx8 ") return NULL;\n", (uint8_t)bits->mask, (uint8_t)bits->bits); break; case 16: - dprintf(fd, "\t\tif ((raw & 0x%" PRIx16 ") != 0x%" PRIx16 ") return NULL;\n", + dprintf(fd, "\tif ((raw & 0x%" PRIx16 ") != 0x%" PRIx16 ") return NULL;\n", (uint16_t)bits->mask, (uint16_t)bits->bits); break; case 32: - dprintf(fd, "\t\tif ((raw & 0x%" PRIx32 ") != 0x%" PRIx32 ") return NULL;\n", + dprintf(fd, "\tif ((raw & 0x%" PRIx32 ") != 0x%" PRIx32 ") return NULL;\n", (uint32_t)bits->mask, (uint32_t)bits->bits); break; case 64: - dprintf(fd, "\t\tif ((raw & 0x%" PRIx64 ") != 0x%" PRIx64 ") return NULL;\n", + dprintf(fd, "\tif ((raw & 0x%" PRIx64 ") != 0x%" PRIx64 ") return NULL;\n", bits->mask, bits->bits); break; @@ -377,7 +414,9 @@ bool define_used_bits_fields(const coding_bits *bits, int fd) rf = &bits->fields[i]; if (!rf->used) continue; - dprintf(fd, "\t\traw_%s = (_raw >> %u) & 0x%llx;\n", rf->name, rf->start, (1ull << rf->length) - 1); + dprintf(fd, "\t"); + write_raw_bitfield(rf, fd); + dprintf(fd, " = (raw >> %u) & 0x%llx;\n", rf->start, (1ull << rf->length) - 1); got_one = true; diff --git a/tools/d2c/bits/manager.h b/tools/d2c/bits/manager.h index f696250..71d9055 100644 --- a/tools/d2c/bits/manager.h +++ b/tools/d2c/bits/manager.h @@ -44,6 +44,8 @@ unsigned int get_raw_bitfield_length(const raw_bitfield *); /* Marque un champ de bits comme étant utile. */ void mark_raw_bitfield_as_used(raw_bitfield *); +/* Imprime la désignation d'un champ de bits dans du code. */ +void write_raw_bitfield(const raw_bitfield *, int); @@ -74,7 +76,7 @@ unsigned int count_coded_bits(const coding_bits *); raw_bitfield *find_named_field_in_bits(const coding_bits *, const char *); /* Déclare les variables C associées aux champs de bits. */ -bool declare_used_bits_fields(const coding_bits *, int, unsigned int); +bool declare_used_bits_fields(const coding_bits *, int); /* Vérifie que les bits fixes correspondent au masque attendu. */ bool check_bits_correctness(const coding_bits *, int); diff --git a/tools/d2c/bits/tokens.l b/tools/d2c/bits/tokens.l index 99fb96d..4879f4f 100644 --- a/tools/d2c/bits/tokens.l +++ b/tools/d2c/bits/tokens.l @@ -29,5 +29,11 @@ [01] { yylvalp->integer = atoi(yytext); return BIT; } +. { + char *msg; + asprintf(&msg, "Unhandled token in d2c bits block: '%s'", yytext); + YY_FATAL_ERROR(msg); + free(msg); + } %% |