From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 590EE385B537 for ; Tue, 15 Aug 2023 20:01:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 590EE385B537 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1692129680; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=x+GZQAVJT4eHYIdjKactX2UUiokdZwdOI3VCPWbnt48=; b=VSGAPkfbWKOvZCA6EbTJMgDQrsGojfuL9ycFaL3RUqu/g8SpPV9GeyB/1ysNmOTftWCxxB J1YHnHKpLAET9wHLkvfxiserksOHORB2K3Q8kZRLv/f5Ac8e4k5vUuXsZONpt7WxqJmYQT OyOSlf/LXcsuBsdyeQkniCWD2w4CSf0= Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-400-eZM5sIovNk-8BDPIq1vDQg-1; Tue, 15 Aug 2023 16:01:18 -0400 X-MC-Unique: eZM5sIovNk-8BDPIq1vDQg-1 Received: by mail-io1-f70.google.com with SMTP id ca18e2360f4ac-7911973a90eso436544739f.3 for ; Tue, 15 Aug 2023 13:01:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692129677; x=1692734477; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=x+GZQAVJT4eHYIdjKactX2UUiokdZwdOI3VCPWbnt48=; b=jp2bypzqS/OOLToO4GhLn3GIRU1EXfVrxhmHuhHfQYg8tPjbkPw1CQTgf/J129JbFy tGYUc+j1MahvZLXxukO8oArrks7YX4TYXLXCDR6VPE1LkMBmVdfTik6vcl/TZgFnd+XQ QMmSkfNl0p+wc/GLVQc6I9Sttz6MtN0eZ8Np0scZlqvU94jeD2nLjPCWJSP6zgIx4aNn q2d+0elIpRIptrCB73xhS9dZosilFbZu57Sx4IOZvZB8sncSBMG05v89zfRz+gaxctsx ynVrLGaDKG1nOIv2r2GvTdA6qgdE+QxLSmQfT/9W7o7SrtVZBhKNHlZfO+eLr+mC9HH2 VA5g== X-Gm-Message-State: AOJu0YwbaTs9SW9/uLob5cOKSD20qfqOU+UTwknnfS7gO4MZq713ZO7O 1VmzzjG7O6jeMe2rpK3fhfger+eNcelKx/Q1O44HULW5Nhz60vAFtvFFam453GWzQQ218yUItgQ 3W9cQPW44kvu1TeC83vasBiw= X-Received: by 2002:a6b:5917:0:b0:786:cd9b:1ccd with SMTP id n23-20020a6b5917000000b00786cd9b1ccdmr15780186iob.0.1692129677526; Tue, 15 Aug 2023 13:01:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQ7lEX7BxRcJzF04tRN9F5eHOZ5Hr9K6TlVCKZ3rj0GgukYJQVn7wrvw6DQylyhDXcu/3Jxy7mJxauAXpdomM= X-Received: by 2002:a6b:5917:0:b0:786:cd9b:1ccd with SMTP id n23-20020a6b5917000000b00786cd9b1ccdmr15780166iob.0.1692129677268; Tue, 15 Aug 2023 13:01:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jason Merrill Date: Tue, 15 Aug 2023 16:00:59 -0400 Message-ID: Subject: Re: Mapping of TREE_CODE to tree_node To: Aaron Lorey Cc: Andrew Pinski , David Malcolm , gcc@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="00000000000053f4d70602fba444" X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --00000000000053f4d70602fba444 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Aug 11, 2023 at 7:31=E2=80=AFPM Aaron Lorey via Gcc wrote: > Am Mo., 3. Juli 2023 um 02:50 Uhr schrieb Andrew Pinski >: > > > > On Sun, Jul 2, 2023 at 5:48=E2=80=AFPM Aaron Lorey via Gcc > wrote: > > > > > > Am Mo., 26. Juni 2023 um 20:09 Uhr schrieb David Malcolm < > dmalcolm@redhat.com>: > > > > > > > > On Mon, 2023-06-26 at 18:59 +0200, Aaron Lorey via Gcc wrote: > > > > > Hello, > > > > > > > > > > this is the first time I am writing to a mailing list. I've tried > > > > > researching the normal procedure but nothing special seems to be > > > > > required. > > > > > > > > > > I'm currently trying to do a complete graph-discovery of GCC's > symtab > > > > > / > > > > > tree_nodes to dump the full internal representation of the > > > > > compilation > > > > > unit. Gitlab: https://gitlab.com/graph-prog/code-database > > > > > > > > > > It is not exceptionally heavy but also not very easy to serialize > the > > > > > internal state to disk. I think this task was simply not consider= ed > > > > > in the > > > > > design. > > > > > > > > > > Reason for writing to the mailing list are the troubles in > connecting > > > > > the > > > > > TREE_CODE enumeration to the appropriate struct tree_node memory > > > > > layout > > > > > without guessing. > > > > > > > > > > Can you provide a mapping of TREE_CODE to tree_node memory layout? > > > > > > > > I don't know that such a mapping exists directly, but have a look at > > > > the functions "tree_code_size" and "tree_size" defined in > gcc/tree.cc. > > > > > > > > You might also find the LTO streaming code of interest; see gcc/lto- > > > > streamer-{in,out}.cc > > > > > > > > Hope this is helpful > > > > Dave > > > > > > > > > > > > > > Thank you for your reply. > > > > > > The tree_size() and tree_code_size() functions are useful, although > incomplete. > > > > > > If I understand correctly, the link time optimization works on the > > > GIMPLE representation. The original syntax tree and symbol table would > > > be preferable. > > > > You could also look into the module support in the C++ front-end, > > `gcc/cp/module.cc ` which does store out the original trees and such. > > > > Thanks, > > Andrew > > > > > > > > Andrew's suggestion might be more what I'm looking for. > > I've now managed to dump the syntax tree of the compilation unit > (tree_function_decl.saved_tree -> tree_exp.operands -> > tree_statement_list.nodes). Thank you very much for the help! > > In order to print out the original code, I need to know which program > code was translated to the individual nodes. Is there a chance to get > the original tokens (or the offsets in the program code file) per > tree_node without modifying the parser? > Generally we try to track the corresponding source location for a lot of things and attach them to the relevant tree nodes (EXPR_LOCATION, DECL_SOURCE_LOCATION). In many cases there is a lot of room for improvement in this. For instance, for a class, instead of just storing the location of the name, we could remember the range from the class-key to the closing brace. Jason --00000000000053f4d70602fba444--