From patchwork Wed Jul 18 16:53:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 171754 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2DC0E2C0081 for ; Thu, 19 Jul 2012 02:54:33 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343235274; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Subject:Message-ID:Mime-Version:Content-Type: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=Rhq4LBjGfMPR1GYPXStK qFcUKHM=; b=uOmKKc9SnDAYjwS6dGHz33RhBT7CnIeAE5IIjbyvzSJU+bFf+wzE ylyXrXHE/N7C2y+6oW40VGiDyykOYm5bppgpYU9vdtIY4V1WE7q6c8RaHszbDD1A o4xLreHsUk030d7vPyrc5F/8UZe5gYX/6b2dnZrx1KouhJCn826e2ZU= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:Subject:Message-ID:Mime-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=yufO+Z+zcExH8TTtEHibd+ti5fv63Ap8PFLC5wmmALDhzjakLTgMm1xKiwX3Rs pKn1Z7jO5qTBBypG26tiHXFQj3T+6c3tfWxgq6hO3TBNewrpPN5yrbShEOX/04kq uO2znTiHMF7ECGe66IXreYf0gQYP4Wf9bVNG2sAqxg5ZU=; Received: (qmail 24616 invoked by alias); 18 Jul 2012 16:54:24 -0000 Received: (qmail 24606 invoked by uid 22791); 18 Jul 2012 16:54:21 -0000 X-SWARE-Spam-Status: No, hits=-6.9 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 18 Jul 2012 16:54:03 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6IGs2Dr032715 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 18 Jul 2012 12:54:02 -0400 Received: from spoyarek (vpn-236-26.phx2.redhat.com [10.3.236.26]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6IGs05s020930 for ; Wed, 18 Jul 2012 12:54:01 -0400 Date: Wed, 18 Jul 2012 22:23:57 +0530 From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Subject: [RESEND-2][PATCH] Allow printing of escaped curly braces in assembler directives with operands Message-ID: <20120718222357.117f8208@spoyarek> Mime-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, Resending. I did not get any responses the last two times and I too forgot about it. Can someone please review this? Thanks, Siddhesh Begin forwarded message: Date: Tue, 3 Apr 2012 18:46:53 +0530 From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Subject: Fw: [PATCH] Allow printing of escaped curly braces in assembler directives with operands Hi, ping? --- Siddhesh Begin forwarded message: Date: Tue, 27 Mar 2012 10:51:37 +0530 From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org Subject: [PATCH] Allow printing of escaped curly braces in assembler directives with operands Hi, An assembler directive with an operand is filtered through output_asm_insn (or asm_fprintf for gcc internal asm() directives) to expand the operand values in the assembler as well as to choose dialects if present. This patch is concerned primarily with the dialects, since their syntax prevent inclusion of assembler strings with curly braces, causing them to be interpreted as dialects. The attached patch allows printing of curly braces in assembler by preceding them with a \\. So to print the following code into assembler: .pushsection ".foo"; .asciz "div { width : 50%% | height=10px }"; .long 42; .popsection The following code needs to be used with this patch: void f() { asm ( ".pushsection \".foo\"; .asciz \"div \\{ width : 50%% | height=10px \\} \"; .long %c0; .popsection" : : "i"(42) ); } The other option to \\ (since it doesn't look as clean) was to use % as an escape character, but I was not sure if that is a better looking option or a worse looking one. I don't mind resubmitting the patch to use %{ and %} to print curly braces if that is acceptable. It is still possible to print curly braces in asm string literals without operands since they do not undergo any transformation. The patch does not introduce any regressions. I have tested this with x86_64 and i686 and it works well with both of them. Regards, Siddhesh gcc/ChangeLog: 2012-03-27 Siddhesh Poyarekar * final.c (output_asm_insn, asm_fprintf): Print curly braces if preceded by an escaped backslash (\\). testsuite/ChangeLog: 2012-03-27 Siddhesh Poyarekar * gcc.dg/asm-braces.c: New test case. diff --git a/gcc/final.c b/gcc/final.c index 718caf1..2393c0f 100644 --- a/gcc/final.c +++ b/gcc/final.c @@ -3444,6 +3444,12 @@ output_asm_insn (const char *templ, rtx *operands) output_operand_lossage ("invalid %%-code"); break; + /* Escaped braces. Print them as is. */ + case '\\': + if (*p == '{' || *p == '}') + c = *p++; + /* FALLTHROUGH */ + default: putc (c, asm_out_file); } @@ -3955,6 +3961,12 @@ asm_fprintf (FILE *file, const char *p, ...) } break; + /* Escaped braces. Print them as is. */ + case '\\': + if (*p == '{' || *p == '}') + c = *p++; + /* FALLTHROUGH */ + default: putc (c, file); } diff --git a/gcc/testsuite/gcc.dg/asm-braces.c b/gcc/testsuite/gcc.dg/asm-braces.c new file mode 100644 index 0000000..4f428c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/asm-braces.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void f() +{ + asm ( ".pushsection \".foo\"; .asciz \"div \\{ width : 50%% | height = 10px \\} \"; .long %c0; .popsection" : : "i"(42) ); +} + +/* { dg-final { scan-assembler "div { width : 50%% | height = 10px }" } } */ -- 1.7.7.6