summaryrefslogtreecommitdiff
path: root/tools/d2c/grammar.y
diff options
context:
space:
mode:
Diffstat (limited to 'tools/d2c/grammar.y')
-rw-r--r--tools/d2c/grammar.y79
1 files changed, 65 insertions, 14 deletions
diff --git a/tools/d2c/grammar.y b/tools/d2c/grammar.y
index 986edd7..02b2671 100644
--- a/tools/d2c/grammar.y
+++ b/tools/d2c/grammar.y
@@ -30,11 +30,23 @@ static void *map_input_data(const char *, size_t *);
#include "args/decl.h"
#include "bits/decl.h"
#include "conv/decl.h"
+#include "format/decl.h"
#include "hooks/decl.h"
#include "rules/decl.h"
#include "syntax/decl.h"
+#define handle_coder_format(c, r) \
+ ({ \
+ encoding_spec *__spec; \
+ operands_format *__format; \
+ bool __status; \
+ __spec = get_current_encoding_spec(c); \
+ __format = get_format_in_encoding_spec(__spec); \
+ __status = load_format_from_raw_line(__format, r); \
+ if (!__status) YYABORT; \
+ })
+
#define handle_coder_bits(c, e, r) \
({ \
encoding_spec *__spec; \
@@ -94,6 +106,7 @@ static void *map_input_data(const char *, size_t *);
%union {
+ char character; /* Simple caractère isolé */
char *string; /* Chaîne de caractères #1 */
const char *cstring; /* Chaîne de caractères #2 */
@@ -124,12 +137,13 @@ YY_DECL;
%token COPYRIGHT
%token TITLE
-%token INS_NAME INS_DETAILS
+%token INS_NAME INS_SEP INS_DETAILS
%token ENCODING
%token TYPE NUMBER
%token ENC_START ENC_END
+%token FORMAT
%token WORD HALF
%token SYNTAX
%token CONV
@@ -140,6 +154,7 @@ YY_DECL;
%type <string> COPYRIGHT INS_NAME
+%type <character> INS_SEP
%type <cstring> INS_DETAILS
%type <string> TYPE
@@ -153,14 +168,27 @@ YY_DECL;
input : name encodings { if (!dump_all_routines_using_coder(coder)) YYABORT; }
-name : COPYRIGHT TITLE INS_NAME { save_notes_for_coder(coder, $1, $3, NULL); }
- | COPYRIGHT TITLE INS_NAME INS_DETAILS { save_notes_for_coder(coder, $1, $3, $4); }
+name : COPYRIGHT TITLE INS_NAME { save_notes_for_coder(coder, $1, $3, '\0', NULL); }
+ | COPYRIGHT TITLE INS_NAME INS_SEP INS_DETAILS { save_notes_for_coder(coder, $1, $3, $4, $5); }
encodings : /* empty */
| encoding encodings
-encoding : ENCODING TYPE NUMBER content { push_encoding_spec(coder, $2, $3); }
+encoding : ENCODING TYPE NUMBER format_content { push_encoding_spec(coder, $2, $3); }
+ | ENCODING format_content { push_encoding_spec(coder, NULL, -1); }
+ | ENCODING TYPE NUMBER content { push_encoding_spec(coder, $2, $3); }
+
+
+/* Définitions à l'aide d'un format défini */
+
+format_content : /* empty */
+ | format format_content
+
+format : FORMAT RAW_LINE { handle_coder_format(coder, $2); }
+
+
+/* Définitions à l'aide de données brutes */
content : /* empty */
@@ -170,7 +198,6 @@ content : /* empty */
| hooks content
| rules content
-
bitfield : HALF RAW_LINE { handle_coder_bits(coder, 16, $2); }
| WORD RAW_LINE { handle_coder_bits(coder, 32, $2); }
@@ -225,7 +252,7 @@ static void show_usage(const char *argv0)
{
printf("\n");
- printf("Usage: %s [options] < file\n", argv0);
+ printf("Usage: %s [options]\n", argv0);
printf("\n");
@@ -234,11 +261,14 @@ static void show_usage(const char *argv0)
printf("\n");
printf("\t-h | --help\t\t\tDisplay this messsage.\n");
+ printf("\t-i | --input <file>\t\tProvide the input file containing the description.\n");
+ printf("\t-t | --type <raw|format>\tSet the type of the input file.\n");
printf("\t-d | --dir <string>\t\tSpecify the main output directory.\n");
printf("\t-a | --arch <string>\t\tDefine the archicture to handle.\n");
printf("\t-H | --header <string>\t\tSet the base of the #ifndef / #define game.\n");
- printf("\t-e | --encoding <string>\tDefine encoding prefixes for files.\n");
+ printf("\t-e | --encoding <none|string>\tDefine encoding prefixes for files.\n");
printf("\t-m | --macro <string>\t\tRegister some conversion functions.\n");
+ printf("\t-p | --prefix <string>\t\tDefine a prefix to format operand type constants (see -t).\n");
printf("\n");
@@ -333,11 +363,13 @@ int main(int argc, char **argv)
{ "help", no_argument, NULL, 'h' },
{ "input", required_argument, NULL, 'i' },
+ { "type", required_argument, NULL, 't' },
{ "dir", required_argument, NULL, 'd' },
{ "arch", required_argument, NULL, 'a' },
{ "header", required_argument, NULL, 'H' },
{ "encoding", required_argument, NULL, 'e' },
{ "macro", required_argument, NULL, 'M' },
+ { "prefix", required_argument, NULL, 'p' },
{ NULL, 0, NULL, 0 }
};
@@ -353,7 +385,7 @@ int main(int argc, char **argv)
while (!has_error)
{
- ret = getopt_long(argc, argv, "hi:d:a:H:e:M:", long_options, &index);
+ ret = getopt_long(argc, argv, "hi:t:d:a:H:e:M:p:", long_options, &index);
if (ret == -1) break;
switch (ret)
@@ -366,6 +398,13 @@ int main(int argc, char **argv)
set_coder_input_file(coder, optarg);
break;
+ case 't':
+ if (strcmp(optarg, "raw") == 0)
+ set_coder_input_type(coder, IOT_RAW);
+ else if (strcmp(optarg, "format") == 0)
+ set_coder_input_type(coder, IOT_FORMAT);
+ break;
+
case 'd':
set_coder_output_directory(coder, optarg);
break;
@@ -380,13 +419,20 @@ int main(int argc, char **argv)
case 'e':
- sep = strchr(optarg, '=');
- has_error = (sep == NULL);
-
- if (!has_error)
+ if (strcmp(optarg, "none") == 0)
+ register_empty_encoding(get_coder_pre_proc(coder));
+
+ else
{
- *sep = '\0';
- register_encoding(get_coder_pre_proc(coder), optarg, sep + 1);
+ sep = strchr(optarg, '=');
+ has_error = (sep == NULL);
+
+ if (!has_error)
+ {
+ *sep = '\0';
+ register_encoding(get_coder_pre_proc(coder), optarg, sep + 1);
+ }
+
}
break;
@@ -404,6 +450,10 @@ int main(int argc, char **argv)
break;
+ case 'p':
+ set_coder_const_prefix(coder, optarg);
+ break;
+
}
}
@@ -412,6 +462,7 @@ int main(int argc, char **argv)
{
show_usage(argv[0]);
result = (need_help ? EXIT_SUCCESS : EXIT_FAILURE);
+ printf("need help ? %d - result = %d vs %d\n", need_help, result, EXIT_SUCCESS);
goto exit;
}