From nobody Wed Nov 19 00:13:59 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1613080590; cv=none; d=zohomail.com; s=zohoarc; b=fVGpcU3fjU5Bvu5ndsZadJwC5mHGyGG4rt7fK0TqIKxhyJt72BMCR2zwONrelCfB5UHVXzQWUwdD5CHI3KQ5s2Gf9OmvBQ5V6tUlIiJDrcgnreMJJwY9XvGp/0XNL2Kw3vLu8w05E5lag2dG2wA4VE9WkrKFMJSF9pQapIu2Rfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613080590; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=8spDaotpUtdVV+Pej9PcYQZUKTvB95PZ+CiOjPT/JT8=; b=LwZuU2PdcsHUV0fxbtkNr+s/GAsk+z7mY9/ma3IJ1+ZZBqTSTWoFj8q15TfflBrUOF/qS24exvxQ37aSWK+VHFEs5fgzGW7/aYP4Z6wxa6l2/ckBJCqOi2jSZxjfVHJfMWHlhnWI3ky9Q1vvs1V2XEOKwL7WrZQZodNNtJnBj70= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613080589924281.537200013002; Thu, 11 Feb 2021 13:56:29 -0800 (PST) Received: from localhost ([::1]:60024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAJwp-000258-Ps for importer@patchew.org; Thu, 11 Feb 2021 16:56:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57074) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAJrr-0006SV-BS for qemu-devel@nongnu.org; Thu, 11 Feb 2021 16:51:19 -0500 Received: from rev.ng ([5.9.113.41]:33251) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAJrj-00011y-Km for qemu-devel@nongnu.org; Thu, 11 Feb 2021 16:51:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=rev.ng; s=dkim; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=8spDaotpUtdVV+Pej9PcYQZUKTvB95PZ+CiOjPT/JT8=; b=Z29/jTHd0GwOPPWpvAaj2S+c6K BYbqclkVlkm+Jogx9z+0ISooJ6lx3bXOZBEodYqZ4+8cjaDVPsHm7hK7l3Zj7R3SI13Mej49kGXNd wVI4HGjW3syDC38smuv9TuX5Xv4FROX9YqOlew1q0xHl2qcmHUWxYP7fsUyrmpONVMW8=; To: qemu-devel@nongnu.org Cc: tsimpson@quicinc.com, bcain@quicinc.com, babush@rev.ng, nizzo@rev.ng, Alessandro Di Federico Subject: [RFC PATCH 07/10] target/hexagon: import lexer for idef-parser Date: Thu, 11 Feb 2021 22:50:48 +0100 Message-Id: <20210211215051.2102435-8-ale.qemu@rev.ng> In-Reply-To: <20210211215051.2102435-1-ale.qemu@rev.ng> References: <20210211215051.2102435-1-ale.qemu@rev.ng> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=5.9.113.41; envelope-from=ale@rev.ng; helo=rev.ng X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Alessandro Di Federico From: Alessandro Di Federico via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Paolo Montesel Signed-off-by: Alessandro Di Federico --- target/hexagon/idef-parser/idef-lexer.lex | 648 ++++++++++++++++++++++ target/hexagon/idef-parser/idef-parser.h | 245 ++++++++ target/hexagon/meson.build | 4 + 3 files changed, 897 insertions(+) create mode 100644 target/hexagon/idef-parser/idef-lexer.lex create mode 100644 target/hexagon/idef-parser/idef-parser.h diff --git a/target/hexagon/idef-parser/idef-lexer.lex b/target/hexagon/ide= f-parser/idef-lexer.lex new file mode 100644 index 0000000000..b0e460b4d4 --- /dev/null +++ b/target/hexagon/idef-parser/idef-lexer.lex @@ -0,0 +1,648 @@ +%option noyywrap noinput nounput +%option 8bit reentrant bison-bridge +%option warn nodefault +%option header-file=3D"idef-parser.yy.h" +%option bison-locations + +%{ +/* + * 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 +#include + +#include "idef-parser.h" +#include "idef-parser.tab.h" + +/* Keep track of scanner position for error message printout */ +#define YY_USER_ACTION yylloc->first_column =3D yylloc->last_column; \ + for (int i =3D 0; yytext[i] !=3D '\0'; i++) { \ + yylloc->last_column++; \ + } + +/* Global Error Counter */ +int error_count; + +%} + +/* Definitions */ +DIGIT [0-9] +LOWER_ID [a-z] +UPPER_ID [A-Z] +ID LOWER_ID|UPPER_ID +INST_NAME [A-Z]+[0-9]_([A-Za-z]|[0-9]|_)+ +HEX_DIGIT [0-9a-fA-F] +REG_ID_32 e|s|d|t|u|v|x|y +REG_ID_64 ee|ss|dd|tt|uu|vv|xx|yy +SYS_ID_32 s|d +SYS_ID_64 ss|dd +LOWER_PRE d|s|t|u|v|e|x|x +ZERO_ONE 0|1 +IMM_ID r|s|S|u|U +VAR_ID [a-zA-Z_][a-zA-Z0-9_]* +SIGN_ID s|u + +/* Tokens */ +%% + +[ \t\f\v]+ { /* Ignore whitespaces. */ } +[\n\r]+ { /* Ignore newlines. */ } + +{INST_NAME} { yylval->string =3D strdup(yytext); + return INAME; } +"fFLOAT" | +"fUNFLOAT" | +"fDOUBLE" | +"fUNDOUBLE" | +"0.0" | +"0x1.0p52" | +"0x1.0p-52" { return FAIL; } +"R"{REG_ID_32}"V" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D GENERAL_PURPOSE; + yylval->rvalue.reg.id =3D yytext[1]; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D false; + return REG; } +"R"{REG_ID_32}"N" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D DOTNEW; + yylval->rvalue.reg.id =3D yytext[1]; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D true; + return REG; } +"R"{REG_ID_64}"V" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D GENERAL_PURPOSE; + yylval->rvalue.reg.id =3D yytext[1]; + yylval->rvalue.reg.bit_width =3D 64; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_dotnew =3D false; + return REG; } +"R"{REG_ID_64}"N" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D DOTNEW; + yylval->rvalue.reg.id =3D yytext[1]; + yylval->rvalue.reg.bit_width =3D 64; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_dotnew =3D true; + return REG; } +"MuV" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D MODIFIER; + yylval->rvalue.reg.id =3D 'u'; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"C"{REG_ID_32}"V" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D yytext[1]; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D false; + return REG; } +"C"{REG_ID_64}"V" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D yytext[1]; + yylval->rvalue.reg.bit_width =3D 64; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_dotnew =3D false; + return REG; } +{IMM_ID}"iV" { + yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.is_unsigned =3D false; + yylval->rvalue.imm.type =3D VARIABLE; + yylval->rvalue.imm.id =3D yytext[0]; + yylval->rvalue.is_dotnew =3D false; + return IMM; } +"P"{LOWER_PRE}"V" { + yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D yytext[1]; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D false; + return PRE; } +"P"{LOWER_PRE}"N" { + yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D yytext[1]; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D true; + return PRE; } +"in R"{REG_ID_32}"V" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D GENERAL_PURPOSE; + yylval->rvalue.reg.id =3D yytext[4]; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D false; + return RREG; } +"in R"{REG_ID_64}"V" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D GENERAL_PURPOSE; + yylval->rvalue.reg.id =3D yytext[4]; + yylval->rvalue.reg.bit_width =3D 64; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_dotnew =3D false; + return RREG; } +"in N"{REG_ID_32}"N" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D DOTNEW; + yylval->rvalue.reg.id =3D yytext[4]; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D true; + return RREG; } +"in N"{REG_ID_64}"N" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D DOTNEW; + yylval->rvalue.reg.id =3D yytext[4]; + yylval->rvalue.reg.bit_width =3D 64; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_dotnew =3D true; + return RREG; } +"in P"{LOWER_PRE}"V" { + yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D yytext[4]; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D false; + return RPRE; } +"in P"{LOWER_PRE}"N" { + yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D yytext[4]; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D true; + return RPRE; } +"in MuV" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D MODIFIER; + yylval->rvalue.reg.id =3D 'u'; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return RREG; } +"in C"{REG_ID_32}"V" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D yytext[4]; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D false; + return RREG; } +"in C"{REG_ID_64}"V" { + yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D yytext[4]; + yylval->rvalue.reg.bit_width =3D 64; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_dotnew =3D false; + return RREG; } +"fGEN_TCG_"{INST_NAME}"(" { return FWRAP; } +"(unsigned int)" { /* Skip c-style casts */ } +"{" { return LBR; } +"}" { return RBR; } +"[" { return LSQ; } +"]" { return RSQ; } +"(" { return LPAR; } +")" { return RPAR; } +"IV1DEAD()" | +"fPAUSE(uiV);" | +";" { return SEMI; } +":" { return COLON; } +"+" { return PLUS; } +"-" { return MINUS; } +"*" { return MUL; } +"**" { return POW; } +"/" { return DIV; } +"%" { return MOD; } +"&" { return AND; } +"|" { return OR; } +"^" { return XOR; } +"~" { return NOT; } +"=3D" { return ASSIGN; } +"+=3D" { return INC; } +"-=3D" { return DEC; } +"++" { return PLUSPLUS; } +"&=3D" { return ANDA; } +"|=3D" { return ORA; } +"^=3D" { return XORA; } +"<" { return LT; } +">" { return GT; } +"<<" { return ASL; } +">>" { return ASR; } +">>>" { return LSR; } +"=3D=3D" { return EQ; } +"!=3D" { return NEQ; } +"<=3D" { return LTE; } +">=3D" { return GTE; } +"&&" { return ANDL; } +"||" { return ORL; } +"!" { return NOTL; } +"," { return COMMA; } +"else" { return ELSE; } +"for" { return FOR; } +"fREAD_IREG" { return ICIRC; } +"fPART1" { return PART1; } +"if" { return IF; } +"fFRAME_SCRAMBLE" { return FSCR; } +"fFRAME_UNSCRAMBLE" { return FSCR; } +"fFRAMECHECK" { return FCHK; } +"Constant_extended" { return CONSTEXT; } +"fCL1_"{DIGIT} { return LOCNT; } +"fBREV_8" { return BREV_8; } +"fBREV_4" { return BREV_4; } +"fbrev" { return BREV; } +"fSXTN" { return SXT; } +"fZXTN" { return ZXT; } +"fDF_MAX" | +"fSF_MAX" | +"fMAX" { return MAX; } +"fDF_MIN" | +"fSF_MIN" | +"fMIN" { return MIN; } +"fABS" { return ABS; } +"fRNDN" { return ROUND; } +"fCRND" { return CROUND; } +"fCRNDN" { return CROUND; } +"fPM_CIRI" { return CIRCADD; } +"fPM_CIRR" { return CIRCADD; } +"fCOUNTONES_"{DIGIT} { return COUNTONES; } +"fSATN" { yylval->sat.set_overflow =3D false; + yylval->sat.is_unsigned =3D false; + return SAT; } +"fVSATN" { yylval->sat.set_overflow =3D true; + yylval->sat.is_unsigned =3D false; + return SAT; } +"fSATUN" { yylval->sat.set_overflow =3D false; + yylval->sat.is_unsigned =3D true; + return SAT; } +"fVSATUN" { yylval->sat.set_overflow =3D true; + yylval->sat.is_unsigned =3D true; + return SAT; } +"fSE32_64" { yylval->cast.bit_width =3D 64; + yylval->cast.is_unsigned =3D false; + return CAST; } +"fCAST4_4u" { yylval->cast.bit_width =3D 32; + yylval->cast.is_unsigned =3D true; + return CAST; } +"fCAST4_8s" { yylval->cast.bit_width =3D 64; + yylval->cast.is_unsigned =3D false; + return CAST; } +"fCAST4_8u" { return CAST4_8U; } +"fCAST4u" { yylval->cast.bit_width =3D 32; + yylval->cast.is_unsigned =3D true; + return CAST; } +"fCAST4s" { yylval->cast.bit_width =3D 32; + yylval->cast.is_unsigned =3D false; + return CAST; } +"fCAST8_8u" { yylval->cast.bit_width =3D 64; + yylval->cast.is_unsigned =3D true; + return CAST; } +"fCAST8u" { yylval->cast.bit_width =3D 64; + yylval->cast.is_unsigned =3D true; + return CAST; } +"fCAST8s" { yylval->cast.bit_width =3D 64; + yylval->cast.is_unsigned =3D false; + return CAST; } +"fGETBIT" { yylval->extract.bit_width =3D 1; + yylval->extract.storage_bit_width =3D 1; + yylval->extract.is_unsigned =3D true; + return EXTRACT; } +"fGETBYTE" { yylval->extract.bit_width =3D 8; + yylval->extract.storage_bit_width =3D 8; + yylval->extract.is_unsigned =3D false; + return EXTRACT; } +"fGETUBYTE" { yylval->extract.bit_width =3D 8; + yylval->extract.storage_bit_width =3D 8; + yylval->extract.is_unsigned =3D true; + return EXTRACT; } +"fGETHALF" { yylval->extract.bit_width =3D 16; + yylval->extract.storage_bit_width =3D 16; + yylval->extract.is_unsigned =3D false; + return EXTRACT; } +"fGETUHALF" { yylval->extract.bit_width =3D 16; + yylval->extract.storage_bit_width =3D 16; + yylval->extract.is_unsigned =3D true; + return EXTRACT; } +"fGETWORD" { yylval->extract.bit_width =3D 32; + yylval->extract.storage_bit_width =3D 64; + yylval->extract.is_unsigned =3D false; + return EXTRACT; } +"fGETUWORD" { yylval->extract.bit_width =3D 32; + yylval->extract.storage_bit_width =3D 64; + yylval->extract.is_unsigned =3D true; + return EXTRACT; } +"fEXTRACTU_BITS" { return EXTBITS; } +"fEXTRACTU_RANGE" { return EXTRANGE; } +"fSETBIT" { yylval->cast.bit_width =3D 1; + yylval->cast.is_unsigned =3D false; + return DEPOSIT; } +"fSETBYTE" { yylval->cast.bit_width =3D 8; + yylval->cast.is_unsigned =3D false; + return DEPOSIT; } +"fSETHALF" { yylval->cast.bit_width =3D 16; + yylval->cast.is_unsigned =3D false; + return SETHALF; } +"fSETWORD" { yylval->cast.bit_width =3D 32; + yylval->cast.is_unsigned =3D false; + return DEPOSIT; } +"fINSERT_BITS" { return INSBITS; } +"fSETBITS" { return SETBITS; } +"fMPY8UU" { yylval->mpy.first_bit_width =3D 8; + yylval->mpy.second_bit_width =3D 8; + yylval->mpy.first_unsigned =3D true; + yylval->mpy.second_unsigned =3D true; + return MPY; } +"fMPY8US" { yylval->mpy.first_bit_width =3D 8; + yylval->mpy.second_bit_width =3D 8; + yylval->mpy.first_unsigned =3D true; + yylval->mpy.second_unsigned =3D false; + return MPY; } +"fMPY8SU" { yylval->mpy.first_bit_width =3D 8; + yylval->mpy.second_bit_width =3D 8; + yylval->mpy.first_unsigned =3D false; + yylval->mpy.second_unsigned =3D true; + return MPY; } +"fMPY8SS" { yylval->mpy.first_bit_width =3D 8; + yylval->mpy.second_bit_width =3D 8; + yylval->mpy.first_unsigned =3D false; + yylval->mpy.second_unsigned =3D false; + return MPY; } +"fMPY16UU" { yylval->mpy.first_bit_width =3D 16; + yylval->mpy.second_bit_width =3D 16; + yylval->mpy.first_unsigned =3D true; + yylval->mpy.second_unsigned =3D true; + return MPY; } +"fMPY16US" { yylval->mpy.first_bit_width =3D 16; + yylval->mpy.second_bit_width =3D 16; + yylval->mpy.first_unsigned =3D true; + yylval->mpy.second_unsigned =3D false; + return MPY; } +"fMPY16SU" { yylval->mpy.first_bit_width =3D 16; + yylval->mpy.second_bit_width =3D 16; + yylval->mpy.first_unsigned =3D false; + yylval->mpy.second_unsigned =3D true; + return MPY; } +"fMPY16SS" { yylval->mpy.first_bit_width =3D 16; + yylval->mpy.second_bit_width =3D 16; + yylval->mpy.first_unsigned =3D false; + yylval->mpy.second_unsigned =3D false; + return MPY; } +"fMPY32UU" { yylval->mpy.first_bit_width =3D 32; + yylval->mpy.second_bit_width =3D 32; + yylval->mpy.first_unsigned =3D true; + yylval->mpy.second_unsigned =3D true; + return MPY; } +"fMPY32US" { yylval->mpy.first_bit_width =3D 32; + yylval->mpy.second_bit_width =3D 32; + yylval->mpy.first_unsigned =3D true; + yylval->mpy.second_unsigned =3D false; + return MPY; } +"fMPY32SU" { yylval->mpy.first_bit_width =3D 32; + yylval->mpy.second_bit_width =3D 32; + yylval->mpy.first_unsigned =3D false; + yylval->mpy.second_unsigned =3D true; + return MPY; } +"fSFMPY" | +"fMPY32SS" { yylval->mpy.first_bit_width =3D 32; + yylval->mpy.second_bit_width =3D 32; + yylval->mpy.first_unsigned =3D false; + yylval->mpy.second_unsigned =3D false; + return MPY; } +"fMPY3216SS" { yylval->mpy.first_bit_width =3D 32; + yylval->mpy.second_bit_width =3D 16; + yylval->mpy.first_unsigned =3D false; + yylval->mpy.second_unsigned =3D false; + return MPY; } +"fMPY3216SU" { yylval->mpy.first_bit_width =3D 32; + yylval->mpy.second_bit_width =3D 16; + yylval->mpy.first_unsigned =3D false; + yylval->mpy.second_unsigned =3D true; + return MPY; } +"fNEWREG" | +"fNEWREG_ST" | +"fIMMEXT" | +"fMUST_IMMEXT" | +"fCAST2_2s" | +"fCAST2_2u" | +"fCAST4_4s" | +"fCAST8_8s" | +"fZE8_16" | +"fSE8_16" | +"fZE16_32" | +"fSE16_32" | +"fZE32_64" | +"fPASS" | +"fECHO" { return IDENTITY; } +"(size8"[us]"_t)" { yylval->cast.bit_width =3D 8; + yylval->cast.is_unsigned =3D ((yytext[6]) =3D= =3D 'u'); + return CAST; } +"(size16"[us]"_t)" { yylval->cast.bit_width =3D 16; + yylval->cast.is_unsigned =3D ((yytext[7]) =3D= =3D 'u'); + return CAST; } +"(int)" { yylval->cast.bit_width =3D 32; + yylval->cast.is_unsigned =3D false; + return CAST; } +"?" { return QMARK; } +"fREAD_PC()" | +"PC" { return PC; } +"fREAD_NPC()" | +"NPC" { return NPC; } +"fGET_LPCFG" | +"USR.LPCFG" { return LPCFG; } +"LOAD_CANCEL(EA)" | +"STORE_CANCEL(EA)" | +"CANCEL" { return CANC; } +"N"{LOWER_ID} { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D GENERAL_PURPOSE; + yylval->rvalue.reg.id =3D yytext[1]; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"N"{LOWER_ID}"N" { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D DOTNEW; + yylval->rvalue.reg.id =3D yytext[1]; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +[rR]{DIGIT}+ { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D GENERAL_PURPOSE; + yylval->rvalue.reg.id =3D atoi(yytext + 1); + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"fREAD_SP()" | +"SP" { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D SP; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"fREAD_FP()" | +"FP" { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D FP; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"fREAD_LR()" | +"LR" { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D LR; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"GP" { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D GP; + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"fREAD_LC"{ZERO_ONE} { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D LC0 + atoi(yytext + 8= ); + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"LC"{ZERO_ONE} { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D LC0 + atoi(yytext + 2= ); + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"fREAD_SA"{ZERO_ONE} { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D SA0 + atoi(yytext + 8= ); + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"SA"{ZERO_ONE} { yylval->rvalue.type =3D REGISTER; + yylval->rvalue.reg.type =3D CONTROL; + yylval->rvalue.reg.id =3D SA0 + atoi(yytext + 2= ); + yylval->rvalue.reg.bit_width =3D 32; + yylval->rvalue.bit_width =3D 32; + return REG; } +"MuN" { return MUN; } +"fREAD_P0()" { yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D '0'; + yylval->rvalue.bit_width =3D 32; + return PRE; } +[pP]{DIGIT} { yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D yytext[1]; + yylval->rvalue.bit_width =3D 32; + return PRE; } +"fLSBNEW(P"{LOWER_PRE}"N)" { yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D yytext[9]; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D true; + return PRE; } +"fLSBNEW0" { yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D '0'; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D true; + return PRE; } +"fLSBNEW1" { yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D '1'; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D true; + return PRE; } +"fLSBNEW1NOT" { yylval->rvalue.type =3D PREDICATE; + yylval->rvalue.pre.id =3D '1'; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_dotnew =3D true; + return PRE; } +"N" { yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.imm.type =3D VARIABLE; + yylval->rvalue.imm.id =3D 'N'; + return IMM; } +"i" { yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.imm.type =3D I; + return IMM; } +{SIGN_ID} { yylval->is_unsigned =3D (yytext[0] =3D=3D 'u'); + return SIGN; + } +"fSF_BIAS()" { yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_unsigned =3D false; + yylval->rvalue.imm.type =3D VALUE; + yylval->rvalue.imm.value =3D 127; + return IMM; } +{DIGIT}+ { yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_unsigned =3D false; + yylval->rvalue.imm.type =3D VALUE; + yylval->rvalue.imm.value =3D atoi(yytext); + return IMM; } +{DIGIT}+"LL" { yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_unsigned =3D false; + yylval->rvalue.imm.type =3D VALUE; + yylval->rvalue.imm.value =3D atoi(yytext); + return IMM; } +"0x"{HEX_DIGIT}+ { yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.bit_width =3D 32; + yylval->rvalue.is_unsigned =3D false; + yylval->rvalue.imm.type =3D VALUE; + yylval->rvalue.imm.value =3D strtol(yytext, NUL= L, 16); + return IMM; } +"0x"{HEX_DIGIT}+"LL" { yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_unsigned =3D false; + yylval->rvalue.imm.type =3D VALUE; + yylval->rvalue.imm.value =3D strtol(yytext, NUL= L, 16); + return IMM; } +"0x"{HEX_DIGIT}+"ULL" { yylval->rvalue.type =3D IMMEDIATE; + yylval->rvalue.bit_width =3D 64; + yylval->rvalue.is_unsigned =3D true; + yylval->rvalue.imm.type =3D VALUE; + yylval->rvalue.imm.value =3D strtoul(yytext, NU= LL, 16); + return IMM; } +"fCONSTLL" { return CONSTLL; } +"fCONSTULL" { return CONSTULL; } +"fLOAD" { return LOAD; } +"fSTORE" { return STORE; } +"fROTL" { return ROTL; } +"fSET_OVERFLOW" { return SETOVF; } +"fDEINTERLEAVE" { return DEINTERLEAVE; } +"fINTERLEAVE" { return INTERLEAVE; } +{VAR_ID} { /* Variable name, we adopt the C names conventi= on */ + yylval->rvalue.type =3D VARID; + yylval->rvalue.var.name =3D strndup(yytext, + ALLOC_NAME_SI= ZE); + /* Default types are int */ + yylval->rvalue.bit_width =3D 32; + if (yylval->rvalue.var.name =3D=3D NULL) { + fprintf(stderr, + "Error: failed to duplicate var nam= e: " + "\"%s\"\n", + yytext); + error_count++; + return -1; /* invalid token */ + } + return VAR; } +"fHINTJR(RsV)" { /* Emit no token */ } +. { fprintf(stderr, + "Error: unexpected token \"%s\"\n", + yytext); + error_count++; + return -1; /* invalid token */ + } + +%% diff --git a/target/hexagon/idef-parser/idef-parser.h b/target/hexagon/idef= -parser/idef-parser.h new file mode 100644 index 0000000000..d08b9c80ea --- /dev/null +++ b/target/hexagon/idef-parser/idef-parser.h @@ -0,0 +1,245 @@ +/* + * 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 + * 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 . + */ + +#ifndef IDEF_PARSER_H +#define IDEF_PARSER_H + +#include +#include +#include + +#define TCGV_NAME_SIZE 7 +#define MAX_WRITTEN_REGS 32 +#define OFFSET_STR_LEN 32 +#define ALLOC_LIST_LEN 32 +#define ALLOC_NAME_SIZE 32 +#define INIT_LIST_LEN 32 +#define OUT_BUF_LEN (1024 * 1024) +#define SIGNATURE_BUF_LEN (128 * 1024) +#define HEADER_BUF_LEN (128 * 1024) + +/* Variadic macros to wrap the buffer printing functions */ +#define EMIT(c, ...) \ + do { \ + (c)->out_c +=3D snprintf((c)->out_buffer + (c)->out_c, \ + OUT_BUF_LEN - (c)->out_c, \ + __VA_ARGS__); \ + } while (0) + +#define EMIT_SIG(c, ...) = \ + do { = \ + (c)->signature_c +=3D snprintf((c)->signature_buffer + (c)->signat= ure_c, \ + SIGNATURE_BUF_LEN - (c)->signature_c,= \ + __VA_ARGS__); = \ + } while (0) + +#define EMIT_HEAD(c, ...) = \ + do { = \ + (c)->header_c +=3D snprintf((c)->header_buffer + (c)->header_c, = \ + SIGNATURE_BUF_LEN - (c)->header_c, = \ + __VA_ARGS__); = \ + } while (0) + +/** + * Type of register, assigned to the HexReg.type field + */ +typedef enum {GENERAL_PURPOSE, CONTROL, MODIFIER, DOTNEW} RegType; + +/** + * Types of control registers, assigned to the HexReg.id field + */ +typedef enum {SP, FP, LR, GP, LC0, LC1, SA0, SA1} CregType; + +/** + * Identifier string of the control registers, indexed by the CregType enum + */ +extern const char *creg_str[]; + +/** + * Semantic record of the REG tokens, identifying registers + */ +typedef struct HexReg { + CregType id; /**< Identifier of the register = */ + RegType type; /**< Type of the register = */ + unsigned bit_width; /**< Bit width of the reg, 32 or 64 bits = */ +} HexReg; + +/** + * Data structure, identifying a TCGv temporary value + */ +typedef struct HexTmp { + int index; /**< Index of the TCGv temporary value */ +} HexTmp; + +/** + * Enum of the possible immediated, an immediate is a value which is known + * at tinycode generation time, e.g. an integer value, not a TCGv + */ +enum ImmUnionTag {I, VARIABLE, VALUE, QEMU_TMP, IMM_PC, IMM_CONSTEXT}; + +/** + * Semantic record of the IMM token, identifying an immediate constant + */ +typedef struct HexImm { + union { + char id; /**< Identifier of the immediate = */ + uint64_t value; /**< Immediate value (for VALUE type immediate= s) */ + uint64_t index; /**< Index of the immediate (for int temp vars= ) */ + }; + enum ImmUnionTag type; /**< Type of the immediate = */ +} HexImm; + +/** + * Semantic record of the PRE token, identifying a predicate + */ +typedef struct HexPre { + char id; /**< Identifier of the predicate = */ +} HexPre; + +/** + * Semantic record of the SAT token, identifying the saturate operator + */ +typedef struct HexSat { + bool set_overflow; /**< Set-overflow feature for the sat operator= */ + bool is_unsigned; /**< Unsigned flag for the saturate operator = */ +} HexSat; + +/** + * Semantic record of the CAST token, identifying the cast operator + */ +typedef struct HexCast { + int bit_width; /**< Bit width of the cast operator = */ + bool is_unsigned; /**< Unsigned flag for the cast operator = */ +} HexCast; + +/** + * Semantic record of the EXTRACT token, identifying the cast operator + */ +typedef struct HexExtract { + int bit_width; /**< Bit width of the extract operator = */ + int storage_bit_width; /**< Actual bit width of the extract operator = */ + bool is_unsigned; /**< Unsigned flag for the extract operator = */ +} HexExtract; + +/** + * Semantic record of the MPY token, identifying the fMPY multiplication + * operator + */ +typedef struct HexMpy { + int first_bit_width; /**< Bit width of the first operand of fMPY op= */ + int second_bit_width; /**< Bit width of the second operand of fMPY = */ + bool first_unsigned; /**< Unsigned flag for the first operand of fM= PY */ + bool second_unsigned; /**< Unsigned flag for second operand of fMPY = */ +} HexMpy; + +/** + * Semantic record of the VARID token, identifying automatic variables + * of the input language + */ +typedef struct HexVar { + char *name; /**< Name of the VARID automatic variable = */ +} HexVar; + +/** + * Data structure uniquely identifying an automatic VARID variable, used f= or + * keeping track of declared variable, so that any variable is declared on= ly + * once, and its properties are propagated through all the subsequent inst= ances + * of that variable + */ +typedef struct Var { + char *name; /**< Name of the VARID automatic variable = */ + uint8_t bit_width; /**< Bit width of the VARID automatic variable= */ + bool is_unsigned; /**< Unsigned flag for the VARID automatic var= */ +} Var; + +/** + * Enum of the possible rvalue types, used in the HexValue.type field + */ +enum RvalueUnionTag {REGISTER, TEMP, IMMEDIATE, PREDICATE, VARID}; + +/** + * Semantic record of the rvalue token, identifying any numeric value, + * immediate or register based. The rvalue tokens are combined together + * through the use of several operators, to encode expressions + */ +typedef struct HexValue { + union { + HexReg reg; /**< rvalue of register type = */ + HexTmp tmp; /**< rvalue of temporary type = */ + HexImm imm; /**< rvalue of immediate type = */ + HexPre pre; /**< rvalue of predicate type = */ + HexVar var; /**< rvalue of automatic variable type = */ + }; + enum RvalueUnionTag type; /**< Type of the rvalue = */ + unsigned bit_width; /**< Bit width of the rvalue = */ + bool is_unsigned; /**< Unsigned flag for the rvalue = */ + bool is_dotnew; /**< rvalue of predicate type is dotnew? = */ + bool is_manual; /**< Opt out of automatic freeing of params = */ +} HexValue; + +/** + * Operator type, used for referencing the correct operator when calling t= he + * gen_bin_op() function, which in turn will generate the correct code to + * execute the operation between the two rvalues + */ +enum OpType {ADD_OP, SUB_OP, MUL_OP, DIV_OP, ASL_OP, ASR_OP, LSR_OP, ANDB_= OP, + ORB_OP, XORB_OP, ANDL_OP, MINI_OP, MAXI_OP, MOD_OP}; + +/** + * Data structure including instruction specific information, to be cleared + * out after the compilation of each instruction + */ +typedef struct Inst { + char *name; /**< Name of the compiled instruction = */ + char *code_begin; /**< Beginning of instruction input code= */ + char *code_end; /**< End of instruction input code = */ + int tmp_count; /**< Index of the last declared TCGv tem= p */ + int qemu_tmp_count; /**< Index of the last declared int temp= */ + int if_count; /**< Index of the last declared if label= */ + int error_count; /**< Number of generated errors = */ + Var allocated[ALLOC_LIST_LEN]; /**< Allocated VARID automatic vars = */ + int allocated_count; /**< Elements contained in allocated[] = */ + HexValue init_list[INIT_LIST_LEN]; /**< List of initialized registers = */ + int init_count; /**< Number of members of init_list = */ +} Inst; + +/** + * Data structure representing the whole translation context, which in a + * reentrant flex/bison parser just like ours is passed between the scanner + * and the parser, holding all the necessary information to perform the + * parsing, this data structure survives between the compilation of differ= ent + * instructions + * + */ +typedef struct Context { + void *scanner; /**< Reentrant parser state pointer = */ + char *input_buffer; /**< Buffer containing the input code = */ + char *out_buffer; /**< Buffer containing the output code = */ + int out_c; /**< Characters emitted into out_buffer = */ + char *signature_buffer; /**< Buffer containing the signatures co= de */ + int signature_c; /**< Characters emitted into sig..._buff= er */ + char *header_buffer; /**< Buffer containing the output code = */ + int header_c; /**< Characters emitted into header buff= er */ + FILE *defines_file; /**< FILE * of the generated header = */ + FILE *output_file; /**< FILE * of the C output file = */ + FILE *enabled_file; /**< FILE * of the list of enabled inst = */ + int total_insn; /**< Number of instructions in input fil= e */ + int implemented_insn; /**< Instruction compiled without errors= */ + Inst inst; /**< Parsing data of the current inst = */ +} Context; + +#endif /* IDEF_PARSER_H */ diff --git a/target/hexagon/meson.build b/target/hexagon/meson.build index e2e6b64766..1a008e7e86 100644 --- a/target/hexagon/meson.build +++ b/target/hexagon/meson.build @@ -208,4 +208,8 @@ idef_parser_input_generated_prep =3D custom_target( command: [idef_parser_dir / 'prepare', '@INPUT@', '-I' + idef_parser_d= ir], ) =20 +flex =3D generator(find_program('flex'), + output: '@PLAINNAME@.yy.c', + arguments: ['-o', '@OUTPUT@', '@INPUT@']) + target_arch +=3D {'hexagon': hexagon_ss} --=20 2.30.0