From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by sourceware.org (Postfix) with ESMTPS id 33EB9385772D for ; Fri, 11 Aug 2023 23:30:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 33EB9385772D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-58419517920so26433497b3.0 for ; Fri, 11 Aug 2023 16:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691796618; x=1692401418; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=T0XZZF+958w+pT/fkyOcjLvSB2xbk3S9Rz7hi5l69Bg=; b=T7/TllNdYTrY7u5hiX1cMviCGaodMbMardInqgEi9FtaYh79D27PsX0mAKQxJa5y5w sBLWn3msDnHmNkogi+dZKwzG0lf2HRJvrzXI5BF3iElV9q+jboTv5zgxyRKlMGzI4JBJ kfPbWapLwCPktY/e6gzCkK/2A9m36IRlTnrq8lxTtRU6QRzafZNx/Itpr95NHmnRktks Zx0+eXBcYWVztRtVLOCN2o+4coeHFaTvQN8MpjDI+puOMkfMV2JHF1oSf+U3s2GBZ3xL 7e0T18jdHlYYbWx7EZMtZX9UbB/khF+iaYD19oR2cQmIl833b6YDeLSuGWXhZ5haBHGP bBXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691796618; x=1692401418; h=content-transfer-encoding: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=T0XZZF+958w+pT/fkyOcjLvSB2xbk3S9Rz7hi5l69Bg=; b=OsZjhhylEC2JADKzFdinAGbdxHfQFwES+yaSM6BriJzDEiitUdh3PuoLhvgSUNyllb /Nu5gva0BY9PysZziQ1WqRGoz0XDOUZvIAYPXudp8v01NwIkb4VrC/TV/Ig+jZ8+Pa2R SJhTx9MldJn/9Jt2gD8nTbHVMY1MzxQzlxgfaliYFeXVFCWQSJxvp3SBV+nPsL5SomuW yxVs7V986q94Nb2ot4XF/CBlnJEuBjotNe/wwNkhIOCdqZgNbOO5FTsJJyRaKT3YjGi3 ObEcLGGSa1zErYvWUEcut+MuGjyNXnJlxZOBKZmK+u50lCAdVaJBevhX15YsL0zdq1DD ySnw== X-Gm-Message-State: AOJu0YyXSy+bIfXVHwJwr0kfPeIFPd1KAnpMmVavV9I6iLydzm83aACP hDFajI+DJiJedvOCZBNdtSnOob7INgJoja3bsl0= X-Google-Smtp-Source: AGHT+IH5lMDlMaxY72PUYEcujURwB4zN5o04XH9GqJxh+9ggTc1eiDe09Y0kySF1GPJ2GzycbFELwNFKqaEgcMEzRzM= X-Received: by 2002:a81:8488:0:b0:589:bbef:9eb7 with SMTP id u130-20020a818488000000b00589bbef9eb7mr3290861ywf.15.1691796618454; Fri, 11 Aug 2023 16:30:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Aaron Lorey Date: Sat, 12 Aug 2023 01:30:07 +0200 Message-ID: Subject: Re: Mapping of TREE_CODE to tree_node To: Andrew Pinski Cc: David Malcolm , gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: 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 : > > > > > > 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 symt= ab > > > > / > > > > 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 t= he > > > > internal state to disk. I think this task was simply not considered > > > > in the > > > > design. > > > > > > > > Reason for writing to the mailing list are the troubles in connecti= ng > > > > 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 inc= omplete. > > > > 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?