From patchwork Tue Dec 6 14:47:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaius Mulley X-Patchwork-Id: 30341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2866983wrr; Tue, 6 Dec 2022 06:57:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf6wOI0/7rIomA4iDjHu00m+N9m4Dz5hNGlhcRoBRJL9d6YruTl6YjkXeXj0pxkRMm1qNMQF X-Received: by 2002:a17:907:cf92:b0:7bf:7a65:b242 with SMTP id ux18-20020a170907cf9200b007bf7a65b242mr33492444ejc.356.1670338636387; Tue, 06 Dec 2022 06:57:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670338636; cv=none; d=google.com; s=arc-20160816; b=ebD8wO33AFUwz6E/jCqMyoAimVcf1iqQo1lbQJRXOABBUiZQw3Cfb2rRVUX76kw0Y4 Plr9IsYsZS1ufPhmVp48NVrw8uDAcjJfm6bBBTdfbRpjKx2Xu3f0iSfSDbD4TmC2Jgyz PPtceZreqSfV2zNn3IX4387SvsJ1f3hvYkX7f/bCbU4KDAk9fWODSONPP6ch71isRY21 lLYIvkyCDlTQ6GgrGgmsMBZiZHqaJrAGzeRemhfQ82AmDE2+fcqWi3HzXuWAeeum8Twm iKGVT1DFaHZIx50BJ+LPooNFAa1qaytZGH8MBjb4xm1DNlNONtqNxaszBlSpiGMt+I/l RnEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:date:message-id:to :subject:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=jd6T5PCvwIqpV4ByEXZ6Ve7LzEBSxBGP10vVjXbS5qw=; b=a7vpMi1d/V9UIBYYfIQekebAXg+bSt5Ud2qNtwABf5IJJiU0rCxQmGyIna5/ANc6oa r9OJj05M2KnI19ayFJSztA6SobudUJ+BFA/s8KxQrd2LJXc2rE2BVafgBUyRSPAhtffx /7qz4fqQ1MeCYXGqrJvMLNyoTB2VUFf9uxdL9+Gk+So+jXMjF1L3BoognEPNVoEGI60R mKotn+FHqcSjygGzxaWQ74zFKOMoRNoMMa/D8ylaODzlhzzIGv8m0lQgkDDGTyt6cyV6 ibON3WyGREK/deuRWJJVFgSSX6rC49UR2RT1jvTbd33tyCLUNwhdeolTxZAViL4j9pc+ Vwxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QdXv1rn3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id r21-20020a056402019500b004699e89601dsi1873662edv.588.2022.12.06.06.57.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 06:57:16 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=QdXv1rn3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8BC34395BC44 for ; Tue, 6 Dec 2022 14:52:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BC34395BC44 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670338349; bh=jd6T5PCvwIqpV4ByEXZ6Ve7LzEBSxBGP10vVjXbS5qw=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QdXv1rn3JFjDHC6JL4p/QiiLE772rSTNemEJQAv844joRQTVvp90oUgEKeLyVmk1U /kqZQZ8FYoiFaKOJ7tFAMx91sjZoupvVggydBSkIzWffWQmg4OHusUsN8VoM7PJlvD tFidxGWl4lGJRjnRy1/jGG7P1juPPihWQmXsvXP8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id C8441384699B for ; Tue, 6 Dec 2022 14:47:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8441384699B Received: by mail-wr1-x42b.google.com with SMTP id w15so23774360wrl.9 for ; Tue, 06 Dec 2022 06:47:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=date:message-id:to:subject:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jd6T5PCvwIqpV4ByEXZ6Ve7LzEBSxBGP10vVjXbS5qw=; b=2sT4tDGtB5IJeRhqV0q5BLRuTtvfAlpa0rnhXUboD1Mx+ZgrYMGXsNuIv3JiiGc/+6 9sGo6oJucAMdssV0nFNJJVZ5p9hFvOY+VzPdfPB5LaruIjmDVXETzKPHYtrOovyxhuLh DUFg4stvme0KLbpDyMgdwCCJMhaS6xyEYQ1fp19feNV7Q+QOIdJRCVu+DQLYQFzgJpQp as8QRjtgDIV6RL7jKKgOMQENHX8qQVsqp1FS4aMbAlFR1t6e2gsWY++4iRoidePzdGKM WofM0WrFtOZlu4RcsqasSUOdxniVUFBQLl/dGiJjI+pKtAHvP4Yzm/J83a1Eaes50IGf v4fg== X-Gm-Message-State: ANoB5pmZUWsjRsGOOG3AxsKlhg8RwJIA8HEXDS2JRh22CvLtmhxZ2e6W v9s7/e1qpIzvTFUQAMMxs5OcRLlbrro= X-Received: by 2002:a5d:4244:0:b0:242:5add:4d76 with SMTP id s4-20020a5d4244000000b002425add4d76mr7049432wrr.632.1670338052466; Tue, 06 Dec 2022 06:47:32 -0800 (PST) Received: from lancelot ([195.147.220.46]) by smtp.gmail.com with ESMTPSA id f18-20020a05600c4e9200b003c6c182bef9sm34943210wmq.36.2022.12.06.06.47.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Dec 2022 06:47:32 -0800 (PST) X-Google-Original-From: Gaius Mulley Received: from gaius by lancelot with local (Exim 4.94.2) (envelope-from ) id 1p2ZEF-004Qgl-Sj for gcc-patches@gcc.gnu.org; Tue, 06 Dec 2022 14:47:27 +0000 Subject: [PATCH v3 13/19] modula2 front end: gimple interface *[g-m]*.cc To: X-Mailer: mail (GNU Mailutils 3.10) Message-Id: Date: Tue, 06 Dec 2022 14:47:27 +0000 X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KAM_SHORT, 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 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-Patchwork-Original-From: Gaius Mulley via Gcc-patches From: Gaius Mulley Reply-To: Gaius Mulley Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751477006024468440?= X-GMAIL-MSGID: =?utf-8?q?1751477006024468440?= This patchset contains the gimple interface. ------8<----------8<----------8<----------8<----------8<----------8<---- diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2linemap.cc --- /dev/null 2022-08-24 16:22:16.888000070 +0100 +++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2linemap.cc 2022-12-06 02:56:51.344774733 +0000 @@ -0,0 +1,254 @@ +/* m2linemap.cc provides an interface to GCC linemaps. + +Copyright (C) 2012-2022 Free Software Foundation, Inc. +Contributed by Gaius Mulley . + +This file is part of GNU Modula-2. + +GNU Modula-2 is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GNU Modula-2 is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Modula-2; see the file COPYING3. If not see +. */ + +#include "gcc-consolidation.h" + +/* Utilize some of the C build routines */ + +#include "../gm2-lang.h" +#include "../m2-tree.h" + +#include "m2assert.h" +#include "m2block.h" +#include "m2decl.h" +#include "m2expr.h" +#include "m2options.h" +#include "m2tree.h" +#include "m2type.h" +#define m2linemap_c +#include "m2linemap.h" + +static int inFile = FALSE; + +#if defined(__cplusplus) +#define EXTERN extern "C" +#else +#define EXTERN +#endif + +/* Start getting locations from a new file. */ + +EXTERN +void +m2linemap_StartFile (void *filename, unsigned int linebegin) +{ + if (inFile) + m2linemap_EndFile (); + linemap_add (line_table, LC_ENTER, false, + xstrdup (reinterpret_cast (filename)), linebegin); + inFile = TRUE; +} + +/* Tell the line table the file has ended. */ + +EXTERN +void +m2linemap_EndFile (void) +{ + linemap_add (line_table, LC_LEAVE, 0, NULL, 0); + inFile = FALSE; +} + +/* Indicate that there is a new source file line number with a + maximum width. */ + +EXTERN +void +m2linemap_StartLine (unsigned int linenumber, unsigned int linesize) +{ + linemap_line_start (line_table, linenumber, linesize); +} + +/* GetLocationColumn, returns a location_t based on the current line + number and column. */ + +EXTERN +location_t +m2linemap_GetLocationColumn (unsigned int column) +{ + return linemap_position_for_column (line_table, column); +} + +/* GetLocationRange, returns a location based on the start column + and end column. */ + +EXTERN +location_t +m2linemap_GetLocationRange (unsigned int start, unsigned int end) +{ + location_t caret = m2linemap_GetLocationColumn (start); + + source_range where; + where.m_start = linemap_position_for_column (line_table, start); + where.m_finish = linemap_position_for_column (line_table, end); + return make_location (caret, where); +} + + +static +int +isSrcLocation (location_t location) +{ + return (location != BUILTINS_LOCATION) && (location != UNKNOWN_LOCATION); +} + + +/* GetLocationBinary, returns a location based on the expression + start caret finish locations. */ + +EXTERN +location_t +m2linemap_GetLocationBinary (location_t caret, location_t start, location_t finish) +{ + if (isSrcLocation (start) && isSrcLocation (finish) && isSrcLocation (caret) + && (m2linemap_GetFilenameFromLocation (start) != NULL)) + { + linemap_add (line_table, LC_ENTER, false, xstrdup (m2linemap_GetFilenameFromLocation (start)), 1); + gcc_assert (inFile); + location_t location = make_location (caret, start, finish); + return location; + } + return caret; +} + +/* GetLineNoFromLocation - returns the lineno given a location. */ + +EXTERN +int +m2linemap_GetLineNoFromLocation (location_t location) +{ + if (isSrcLocation (location) && (!M2Options_GetCpp ())) + { + expanded_location xl = expand_location (location); + return xl.line; + } + return 0; +} + +/* GetColumnNoFromLocation - returns the columnno given a location. */ + +EXTERN +int +m2linemap_GetColumnNoFromLocation (location_t location) +{ + if (isSrcLocation (location) && (!M2Options_GetCpp ())) + { + expanded_location xl = expand_location (location); + return xl.column; + } + return 0; +} + +/* GetFilenameFromLocation - returns the filename given a location. */ + +EXTERN +const char * +m2linemap_GetFilenameFromLocation (location_t location) +{ + if (isSrcLocation (location) && (!M2Options_GetCpp ())) + { + expanded_location xl = expand_location (location); + return xl.file; + } + return NULL; +} + +/* ErrorAt - issue an error message. */ + +EXTERN +void +m2linemap_ErrorAt (location_t location, char *message) +{ + error_at (location, message); +} + +/* m2linemap_ErrorAtf - wraps up an error message. */ + +void +m2linemap_ErrorAtf (location_t location, const char *message, ...) +{ + diagnostic_info diagnostic; + va_list ap; + rich_location richloc (line_table, location); + + va_start (ap, message); + diagnostic_set_info (&diagnostic, message, &ap, &richloc, DK_ERROR); + diagnostic_report_diagnostic (global_dc, &diagnostic); + va_end (ap); +} + +/* m2linemap_WarningAtf - wraps up a warning message. */ + +void +m2linemap_WarningAtf (location_t location, const char *message, ...) +{ + diagnostic_info diagnostic; + va_list ap; + rich_location richloc (line_table, location); + + va_start (ap, message); + diagnostic_set_info (&diagnostic, message, &ap, &richloc, DK_WARNING); + diagnostic_report_diagnostic (global_dc, &diagnostic); + va_end (ap); +} + +/* m2linemap_NoteAtf - wraps up a note message. */ + +void +m2linemap_NoteAtf (location_t location, const char *message, ...) +{ + diagnostic_info diagnostic; + va_list ap; + rich_location richloc (line_table, location); + + va_start (ap, message); + diagnostic_set_info (&diagnostic, message, &ap, &richloc, DK_NOTE); + diagnostic_report_diagnostic (global_dc, &diagnostic); + va_end (ap); +} + +/* m2linemap_internal_error - allow Modula-2 to use the GCC internal error. */ + +void +m2linemap_internal_error (const char *message) +{ + internal_error (message); +} + +/* UnknownLocation - return the predefined location representing an + unknown location. */ + +EXTERN +location_t +m2linemap_UnknownLocation (void) +{ + return UNKNOWN_LOCATION; +} + +/* BuiltinsLocation - return the predefined location representing a + builtin. */ + +EXTERN +location_t +m2linemap_BuiltinsLocation (void) +{ + return BUILTINS_LOCATION; +} diff -ruw /dev/null gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2misc.cc --- /dev/null 2022-08-24 16:22:16.888000070 +0100 +++ gcc-git-devel-modula2/gcc/m2/gm2-gcc/m2misc.cc 2022-12-06 02:56:51.344774733 +0000 @@ -0,0 +1,56 @@ +/* m2misc.cc miscellaneous tree debugging functions. + +Copyright (C) 2012-2022 Free Software Foundation, Inc. +Contributed by Gaius Mulley . + +This file is part of GNU Modula-2. + +GNU Modula-2 is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GNU Modula-2 is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Modula-2; see the file COPYING3. If not see +. */ + +#include "gcc-consolidation.h" + +#include "../m2-tree.h" +#include "tree-iterator.h" + +#define m2misc_c +#include "m2block.h" +#include "m2misc.h" +#include "m2tree.h" + +/* DebugTree - display the tree, t. */ + +void +m2misc_DebugTree (tree t) +{ + debug_tree (t); +} + +/* DebugTree - display the tree, t. */ + +void +m2misc_DebugTreeChain (tree t) +{ + for (; (t != NULL); t = TREE_CHAIN (t)) + debug_tree (t); +} + +/* DebugTree - display the tree, t. */ + +void +m2misc_printStmt (void) +{ + if (m2block_cur_stmt_list () != NULL) + debug_tree (m2block_cur_stmt_list ()); +}