From patchwork Tue Apr 3 13:16:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 150442 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 AE523B6FE9 for ; Tue, 3 Apr 2012 23:16:23 +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=1334063783; 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=jDWhDjFdMr8gIoh5rT/W oDqzASg=; b=Bomc3r6mXzdN8CJJGFWBbCgE8qAhp1FGqK3osXGU1TBVJJ9sy9Wh +ovJFM5tdlOvn7bBuR3s/7rUTp7aqt7QEU4fjdE6RK6rYjwjZ1BO3Oz1F8YDIG7v SHHlpTy8p79TswhHH7lo6kt251gWjkhMUEB0yGip1mbSCfO+QN37ruE= 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=hntHx1FSQQf/Lzf5DEntoKwvKXat0F7mFtLot9A8YOIinWa0eshA4lLhMv6N0e jMtGHTAuyHihm6yHAD6mlAZmTFJTMa7WFfWwEXNaPpJjarpiZKjL+SCafoi0AFK5 MxR/KZzWvHGwaIdYVn8zfU1t4uqtMSUVZP9auErSXocx4=; Received: (qmail 18674 invoked by alias); 3 Apr 2012 13:16:19 -0000 Received: (qmail 18665 invoked by uid 22791); 3 Apr 2012 13:16:18 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, MAY_BE_FORGED, 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; Tue, 03 Apr 2012 13:15:59 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q33DFw4E009173 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 3 Apr 2012 09:15:59 -0400 Received: from spoyarek (dhcp233-8.pnq.redhat.com [10.65.223.8] (may be forged)) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q33DFs2M006205 for ; Tue, 3 Apr 2012 09:15:55 -0400 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 Message-ID: <20120403184653.40fd16fa@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, 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