From nobody Thu Nov 13 22:06:42 2025 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@quicinc.com; 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=fail(p=none dis=none) header.from=quicinc.com ARC-Seal: i=1; a=rsa-sha256; t=1582909153; cv=none; d=zohomail.com; s=zohoarc; b=Py0UkFESQt3CF8biC7oGE4e7tBwLRIiIpAXgJODZVLRa+f7aXgpVVSNwiXjcs0Eodbv7rI2aracLePKaJ5cJZ5y/kBGAc0vBcbqqnL0ROuUuTchaS1aRH6M4hmqv0K4dmRtoBFy7flTPrYvUeK1KXKol55yZ7O6qdo5PY+uS0FM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582909153; h=Content-Type: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:References:Sender:Subject:To; bh=lDXRczXbSjQqnrjxsxyR7JmtcZU6E4pY6Xovl1kDpLQ=; b=ABPEwkiR13Ati8+eERLFkiAL5XRmqOKCxxJTfQf4X/gzY7qYCvhW0gd0tmpwWZeoeW4zwnlQw+H69HTiWJerMp4MO2Web56qiSFDJUEmqMN1HMmTm5OR8PE4sZzzh0UYbjSj2ukbQVWxZCdFbJoYW1hpHB7/PZ3NudxOjd2HN80= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@quicinc.com; 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=fail 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 1582909153583545.4914621030791; Fri, 28 Feb 2020 08:59:13 -0800 (PST) Received: from localhost ([::1]:50804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7iym-0000l0-C5 for importer@patchew.org; Fri, 28 Feb 2020 11:59:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:57742) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7ike-0002p6-BI for qemu-devel@nongnu.org; Fri, 28 Feb 2020 11:44:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7ikb-0005YK-LZ for qemu-devel@nongnu.org; Fri, 28 Feb 2020 11:44:36 -0500 Received: from alexa-out-sd-02.qualcomm.com ([199.106.114.39]:27035) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j7ikb-0005Ug-BP for qemu-devel@nongnu.org; Fri, 28 Feb 2020 11:44:33 -0500 Received: from unknown (HELO ironmsg04-sd.qualcomm.com) ([10.53.140.144]) by alexa-out-sd-02.qualcomm.com with ESMTP; 28 Feb 2020 08:44:30 -0800 Received: from vu-tsimpson-aus.qualcomm.com (HELO vu-tsimpson1-aus.qualcomm.com) ([10.222.150.1]) by ironmsg04-sd.qualcomm.com with ESMTP; 28 Feb 2020 08:44:30 -0800 Received: by vu-tsimpson1-aus.qualcomm.com (Postfix, from userid 47164) id 231BA1102; Fri, 28 Feb 2020 10:44:30 -0600 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1582908273; x=1614444273; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lDXRczXbSjQqnrjxsxyR7JmtcZU6E4pY6Xovl1kDpLQ=; b=pFZhahSL/vVXFRTvv1uFOY+sGbGvN1LwbJ5S8ZFhNS2m17tOPZOMR5u+ VvUVbPwtPe96q/oHXNyrJkPIoheDw0Bk0exuQ9zDfi6CXWWZKtE3Mrf0V H4Gql+sitBU5sxIKaOv4LxheXikeN50mAnF3FkFX5DI6CJwJDSZXYo/Fu Y=; From: Taylor Simpson To: qemu-devel@nongnu.org Subject: [RFC PATCH v2 27/67] Hexagon generator phase 2 - printinsn-generated.h Date: Fri, 28 Feb 2020 10:43:23 -0600 Message-Id: <1582908244-304-28-git-send-email-tsimpson@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582908244-304-1-git-send-email-tsimpson@quicinc.com> References: <1582908244-304-1-git-send-email-tsimpson@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 199.106.114.39 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: , Cc: riku.voipio@iki.fi, richard.henderson@linaro.org, laurent@vivier.eu, Taylor Simpson , philmd@redhat.com, aleksandar.m.mail@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Data for printing (disassembling) each instruction (format string + operand= s) Signed-off-by: Taylor Simpson --- target/hexagon/do_qemu.py | 151 ++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 151 insertions(+) diff --git a/target/hexagon/do_qemu.py b/target/hexagon/do_qemu.py index 0c7643a..32543c8 100755 --- a/target/hexagon/do_qemu.py +++ b/target/hexagon/do_qemu.py @@ -892,3 +892,154 @@ realf.write(f.getvalue()) realf.close() f.close() =20 +## +## Generate the printinsn_generated.h file +## Data for printing each instruction (format string + operands) +## +def regprinter(m): + str =3D m.group(1) + str +=3D ":".join(["%d"]*len(m.group(2))) + str +=3D m.group(3) + if ('S' in m.group(1)) and (len(m.group(2)) =3D=3D 1): + str +=3D "/%s" + elif ('C' in m.group(1)) and (len(m.group(2)) =3D=3D 1): + str +=3D "/%s" + return str + +# Regular expression that matches any operator that contains '=3D' charact= er: +opswithequal_re =3D '[-+^&|!<>=3D]?=3D' +# Regular expression that matches any assignment operator. +assignment_re =3D '[-+^&|]?=3D' + +# Out of the operators that contain the =3D sign, if the operator is also = an +# assignment, spaces will be added around it, unless it's enclosed within +# parentheses, or spaces are already present. + +equals =3D re.compile(opswithequal_re) +assign =3D re.compile(assignment_re) + +def spacify(s): + slen =3D len(s) + paren_count =3D {} + i =3D 0 + pc =3D 0 + while i < slen: + c =3D s[i] + if c =3D=3D '(': + pc +=3D 1 + elif c =3D=3D ')': + pc -=3D 1 + paren_count[i] =3D pc + i +=3D 1 + + # Iterate over all operators that contain the equal sign. If any + # match is also an assignment operator, add spaces around it if + # the parenthesis count is 0. + pos =3D 0 + out =3D [] + for m in equals.finditer(s): + ms =3D m.start() + me =3D m.end() + # t is the string that matched opswithequal_re. + t =3D m.string[ms:me] + out +=3D s[pos:ms] + pos =3D me + if paren_count[ms] =3D=3D 0: + # Check if the entire string t is an assignment. + am =3D assign.match(t) + if am and len(am.group(0)) =3D=3D me-ms: + # Don't add spaces if they are already there. + if ms > 0 and s[ms-1] !=3D ' ': + out.append(' ') + out +=3D t + if me < slen and s[me] !=3D ' ': + out.append(' ') + continue + # If this is not an assignment, just append it to the output + # string. + out +=3D t + + # Append the remaining part of the string. + out +=3D s[pos:len(s)] + return ''.join(out) + +immext_casere =3D re.compile(r'IMMEXT\(([A-Za-z])') + +f =3D StringIO() + +for tag in tags: + if not behdict[tag]: continue + extendable_upper_imm =3D False + extendable_lower_imm =3D False + m =3D immext_casere.search(semdict[tag]) + if m: + if m.group(1).isupper(): + extendable_upper_imm =3D True + else: + extendable_lower_imm =3D True + beh =3D behdict[tag] + beh =3D regre.sub(regprinter,beh) + beh =3D absimmre.sub(r"#%s0x%x",beh) + beh =3D relimmre.sub(r"PC+%s%d",beh) + beh =3D spacify(beh) + # Print out a literal "%s" at the end, used to match empty string + # so C won't complain at us + if ("A_VECX" in attribdict[tag]): macname =3D "DEF_VECX_PRINTINFO" + else: macname =3D "DEF_PRINTINFO" + f.write('%s(%s,"%s%%s"' % (macname,tag,beh)) + regs_or_imms =3D reg_or_immre.findall(behdict[tag]) + ri =3D 0 + seenregs =3D {} + for allregs,a,b,c,d,allimm,immlett,bits,immshift in regs_or_imms: + if a: + #register + if b in seenregs: + regno =3D seenregs[b] + else: + regno =3D ri + if len(b) =3D=3D 1: + f.write(',REGNO(%d)' % regno) + if 'S' in a: + f.write(',sreg2str(REGNO(%d))' % regno) + elif 'C' in a: + f.write(',creg2str(REGNO(%d))' % regno) + elif len(b) =3D=3D 2: + f.write(',REGNO(%d)+1,REGNO(%d)' % (regno,regno)) + elif len(b) =3D=3D 4: + f.write(',REGNO(%d)^3,REGNO(%d)^2,REGNO(%d)^1,REGNO(%d)' %= \ + (regno,regno,regno,regno)) + else: + print("Put some stuff to handle quads here") + if b not in seenregs: + seenregs[b] =3D ri + ri +=3D 1 + else: + #immediate + if (immlett.isupper()): + if extendable_upper_imm: + if immlett in 'rR': + f.write(',insn->extension_valid?"##":""') + else: + f.write(',insn->extension_valid?"#":""') + else: + f.write(',""') + ii =3D 1 + else: + if extendable_lower_imm: + if immlett in 'rR': + f.write(',insn->extension_valid?"##":""') + else: + f.write(',insn->extension_valid?"#":""') + else: + f.write(',""') + ii =3D 0 + f.write(',IMMNO(%d)' % ii) + # append empty string so there is at least one more arg + f.write(',"")\n') + +realf =3D open('printinsn_generated.h','w') +realf.write(f.getvalue()) +realf.close() +f.close() + + --=20 2.7.4