From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by sourceware.org (Postfix) with ESMTPS id 89D853858434 for ; Wed, 1 Sep 2021 21:27:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 89D853858434 Received: by mail-vs1-xe36.google.com with SMTP id bf15so1134749vsb.0 for ; Wed, 01 Sep 2021 14:27:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ctvnyau/mnocjXVSAiENEv3efXtjjd5asvYuuclJdko=; b=GQgPcdwY0AmkGLq0eCd/uDUCul4dZty/dHU4qfUu5IfvRFoQy5TqDYJhO5UeoT89nA qUnWkLmdYMDEZLeFexBhooHgz1yduRlED9n4Yy8dLE28njfpxx3708Vnh4z3pkuz1+Yj EIl3xkcU0yAk1clh03WBTPubMELGiOV15s0pc/DT+bTuZepa/PIzanwpK/OE5BwL58Bs vpLKP242JYCklcFbPzqUdbhRnc8mknwug8CC4O2ew63fDdXepZmpv+7HvrQUqMntgWOs y4G4OsAUityAyI7fFa7hh+HgNZYXFV08VAR9a3T1dA3dkBi5NDkL/j92ti0OYcX3R9or nQbw== X-Gm-Message-State: AOAM530hscCqOUjlmkOd/QwFSDO26iGqW6IspzV846dT2Bn8KzHoIEaz tLzJHamN5zk5p2QalEYLEJeAyCT3VogPv6EP0LXs6xQdTVo= X-Google-Smtp-Source: ABdhPJwKYlB4m+AKX44DjLFW9UAWdV4ltXeGkATXchDqPZ+xVVBrnBBu5r5889sNDbICirsACSmeRr9QYBttWXkOldg= X-Received: by 2002:a67:c194:: with SMTP id h20mr1459910vsj.23.1630531664014; Wed, 01 Sep 2021 14:27:44 -0700 (PDT) MIME-Version: 1.0 References: <20210831111949.1162022-1-yunqiang.su@cipunited.com> In-Reply-To: <20210831111949.1162022-1-yunqiang.su@cipunited.com> From: Andrew Pinski Date: Wed, 1 Sep 2021 14:27:31 -0700 Message-ID: Subject: Re: [PATCH v3] md/define_c_enum: support value assignation To: YunQiang Su Cc: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, MEDICAL_SUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Sep 2021 21:27:54 -0000 On Tue, Aug 31, 2021 at 4:22 AM YunQiang Su wrote: > > Currently, the enums from define_c_enum and define_enum can only > has values one by one from 0. > > In fact we can support the behaviour just like C, aka like > (define_enum "mips_isa" [(mips1 1) mips2 (mips32 32) mips32r2]), > then we can get > enum mips_isa { > MIPS_ISA_MIPS1 = 1, > MIPS_ISA_MIPS2 = 2, > MIPS_ISA_MIPS32 = 32, > MIPS_ISA_MIPS32R2 = 33 > }; > > gcc/ChangeLog: > * read-md.c (md_reader::handle_enum): support value assignation. > * doc/md.texi: record define_c_enum value assignation support. > --- > gcc/doc/md.texi | 4 ++++ > gcc/read-md.c | 21 +++++++++++++++++---- > 2 files changed, 21 insertions(+), 4 deletions(-) > > diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi > index f8047aefc..2b41cb7fb 100644 > --- a/gcc/doc/md.texi > +++ b/gcc/doc/md.texi > @@ -11074,6 +11074,8 @@ The syntax is as follows: > (define_c_enum "@var{name}" [ > @var{value0} > @var{value1} > + (@var{value32} 32) > + @var{value33} > @dots{} > @var{valuen} > ]) > @@ -11086,6 +11088,8 @@ in @file{insn-constants.h}: > enum @var{name} @{ > @var{value0} = 0, > @var{value1} = 1, > + @var{value32} = 32, > + @var{value33} = 33, > @dots{} > @var{valuen} = @var{n} > @}; > diff --git a/gcc/read-md.c b/gcc/read-md.c > index bb419e0f6..0fbe924d1 100644 > --- a/gcc/read-md.c > +++ b/gcc/read-md.c > @@ -902,7 +902,8 @@ void > md_reader::handle_enum (file_location loc, bool md_p) > { > char *enum_name, *value_name; > - struct md_name name; > + unsigned int cur_value; > + struct md_name name, value; > struct enum_type *def; > struct enum_value *ev; > void **slot; > @@ -928,6 +929,7 @@ md_reader::handle_enum (file_location loc, bool md_p) > *slot = def; > } > > + cur_value = def->num_values; > require_char_ws ('['); > > while ((c = read_skip_spaces ()) != ']') > @@ -937,8 +939,18 @@ md_reader::handle_enum (file_location loc, bool md_p) > error_at (loc, "unterminated construct"); > exit (1); > } > - unread_char (c); > - read_name (&name); > + if (c == '(') > + { > + read_name (&name); > + read_name (&value); > + require_char_ws (')'); > + cur_value = atoi(value.string); We really should be avoiding adding atoi. Yes there are uses already in the source but https://gcc.gnu.org/PR44574 exists to track those uses. Thanks, Andrew > + } > + else > + { > + unread_char (c); > + read_name (&name); > + } > > ev = XNEW (struct enum_value); > ev->next = 0; > @@ -954,11 +966,12 @@ md_reader::handle_enum (file_location loc, bool md_p) > ev->name = value_name; > } > ev->def = add_constant (get_md_constants (), value_name, > - md_decimal_string (def->num_values), def); > + md_decimal_string (cur_value), def); > > *def->tail_ptr = ev; > def->tail_ptr = &ev->next; > def->num_values++; > + cur_value++; > } > } > > -- > 2.30.2 >