summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2016-02-10 12:09:38 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2016-02-10 12:09:38 (GMT)
commitdbd5e7fdfd43fba609fce3fafdcd38d704554d99 (patch)
tree5811a602d34993598eeea5ea56b1efc3b93f9c63 /tools
parent465488d5b231c2552116a305c48b5fcccea55a09 (diff)
Included indications to load the proper pool constants in Dalvik operands.
Diffstat (limited to 'tools')
-rw-r--r--tools/d2c/format/grammar.y7
-rw-r--r--tools/d2c/format/manager.c37
-rw-r--r--tools/d2c/format/manager.h2
-rw-r--r--tools/d2c/format/tokens.l6
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; }
%%