Re: [RFC PATCH 08/10] target/hexagon: import parser for idef-parser

2021-02-25 Thread Alessandro Di Federico via
On Sun, 14 Feb 2021 08:56:11 -0800
Richard Henderson  wrote:

> What version of bison are you using?

We were using a rather recent version of bison (3.7.5), but it's not
strictly required.

Fixed in v2.

-- 
Alessandro Di Federico
rev.ng



Re: [RFC PATCH 08/10] target/hexagon: import parser for idef-parser

2021-02-14 Thread Richard Henderson
On 2/11/21 1:50 PM, Alessandro Di Federico via wrote:
> +%define parse.error detailed

/usr/share/bison/skeletons/bison.m4:1033: error: invalid error_verbose value:
/usr/share/bison/skeletons/bison.m4:1033: the top level
/home/rth/qemu/git-hex/target/hexagon/idef-parser/idef-parser.y:35.1-28: error:
invalid value for %define variable 'parse.error': 'detailed'
   35 | %define parse.error detailed
  | ^~~~
/home/rth/qemu/git-hex/target/hexagon/idef-parser/idef-parser.y:35.1-28:
accepted value: 'simple'
/home/rth/qemu/git-hex/target/hexagon/idef-parser/idef-parser.y:35.1-28:
accepted value: 'verbose'

What version of bison are you using?


r~



[RFC PATCH 08/10] target/hexagon: import parser for idef-parser

2021-02-11 Thread Alessandro Di Federico via
From: Paolo Montesel 

Signed-off-by: Alessandro Di Federico 
---
 target/hexagon/idef-parser/idef-parser.y| 1248 
 target/hexagon/idef-parser/parser-helpers.c | 1925 +++
 target/hexagon/idef-parser/parser-helpers.h |  293 +++
 target/hexagon/meson.build  |   22 +-
 4 files changed, 3487 insertions(+), 1 deletion(-)
 create mode 100644 target/hexagon/idef-parser/idef-parser.y
 create mode 100644 target/hexagon/idef-parser/parser-helpers.c
 create mode 100644 target/hexagon/idef-parser/parser-helpers.h

diff --git a/target/hexagon/idef-parser/idef-parser.y 
b/target/hexagon/idef-parser/idef-parser.y
new file mode 100644
index 00..80490101ca
--- /dev/null
+++ b/target/hexagon/idef-parser/idef-parser.y
@@ -0,0 +1,1248 @@
+%{
+/*
+ * Copyright(c) 2019-2020 rev.ng Srls. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; withOUT even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see .
+ */
+
+#include "idef-parser.h"
+#include "parser-helpers.h"
+#include "idef-parser.tab.h"
+#include "idef-parser.yy.h"
+
+/* Uncomment this to disable yyasserts */
+/* #define NDEBUG */
+
+#define ERR_LINE_CONTEXT 40
+
+%}
+
+%lex-param {void *scanner}
+%parse-param {void *scanner}
+%parse-param {Context *c}
+
+%define parse.error detailed
+%define parse.lac full
+%define api.pure full
+
+%locations
+
+%union {
+char *string;
+HexValue rvalue;
+HexSat sat;
+HexCast cast;
+HexExtract extract;
+HexMpy mpy;
+bool is_unsigned;
+int index;
+}
+
+/* Tokens */
+%start input
+
+%expect 1
+
+%token INAME DREG DIMM DPRE DEA RREG WREG FREG FIMM RPRE WPRE FPRE FWRAP FEA
+%token VAR LBR RBR LPAR RPAR LSQ RSQ SEMI COLON PLUS MINUS MUL POW DIV MOD ABS
+%token CROUND ROUND CIRCADD COUNTONES AND OR XOR NOT ASSIGN INC DEC ANDA ORA
+%token XORA PLUSPLUS LT GT ASL ASR LSR EQ NEQ LTE GTE MIN MAX ANDL ORL NOTL
+%token COMMA FOR ICIRC IF MUN FSCR FCHK SXT ZXT NEW CONSTEXT LOCNT BREV SIGN
+%token LOAD STORE CONSTLL CONSTULL PC NPC LPCFG CANC QMARK IDENTITY PART1
+%token BREV_4 BREV_8 ROTL INSBITS SETBITS EXTBITS EXTRANGE CAST4_8U SETOVF FAIL
+%token DEINTERLEAVE INTERLEAVE
+
+%token  REG IMM PRE
+%token  ELSE
+%token  MPY
+%token  SAT
+%token  CAST DEPOSIT SETHALF
+%token  EXTRACT
+%type  INAME
+%type  rvalue lvalue VAR assign_statement pre
+%type  DREG DIMM DPRE RREG RPRE FAIL
+%type  if_stmt IF
+%type  SIGN
+
+/* Operator Precedences */
+%left MIN MAX
+%left LPAR
+%left COMMA
+%left ASSIGN
+%right CIRCADD
+%right INC DEC ANDA ORA XORA
+%left QMARK COLON
+%left ORL
+%left ANDL
+%left OR
+%left XOR ANDOR
+%left AND
+%left EQ NEQ
+%left LT GT LTE GTE
+%left ASL ASR LSR
+%right ABS
+%left MINUS PLUS
+%left POW
+%left MUL DIV MOD MPY
+%right NOT NOTL
+%left LSQ
+%left NEW
+%right CAST
+%right LOCNT BREV
+
+/* Bison Grammar */
+%%
+
+/* Input file containing the description of each hexagon instruction */
+input : instructions
+{
+YYACCEPT;
+}
+;
+
+instructions : instruction instructions
+| %empty
+;
+
+instruction : INAME
+{
+/* Early-free if the parser failed on the previous instruction */
+free_instruction(c);
+
+c->total_insn++;
+c->inst.name = $1;
+emit_header(c);
+}
+arguments
+{
+EMIT_SIG(c, ")");
+EMIT_HEAD(c, "{\n");
+
+/* Initialize declared but uninitialized registers, but only for */
+/* non-conditional instructions */
+for (int i = 0; i < c->inst.init_count; i++) {
+bool is64 = c->inst.init_list[i].bit_width == 64;
+const char *type = is64 ? "i64" : "i32";
+if (c->inst.init_list[i].type == REGISTER) {
+OUT(c, &@1, "tcg_gen_movi_", type,
+"(", &(c->inst.init_list[i]), ", 0);\n");
+} else if (c->inst.init_list[i].type == PREDICATE) {
+OUT(c, &@1, "tcg_gen_movi_", type,
+"(", &(c->inst.init_list[i]), ", 0);\n");
+}
+}
+}
+code
+{
+if (c->inst.error_count != 0) {
+fprintf(stderr,
+"Parsing of instruction %s generated %d errors!\n",
+c->inst.name,
+c->inst.error_count);
+EMIT(c, "assert(false && \"This instruction is not implemented!\");");
+} else {
+free_variables(c, &@1);
+c->implemented_insn++;
+fprintf(c->enabled_file, "%s\n", c->inst.name);
+emit_footer(c);
+commit(c);
+}
+free_instruction(c);
+}
+| error /* Recover gracef