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: 61586 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA5293875B6A for ; Tue, 6 Dec 2022 14:52:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DA5293875B6A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670338332; bh=jd6T5PCvwIqpV4ByEXZ6Ve7LzEBSxBGP10vVjXbS5qw=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=sO8EgYb2uvyVWQKV81uahxJzM6cYoxkSfm9p1rEGQcg1LraT2fQG/uMIv7f5EAbFH tJWGm5j/g3Cg/j74FSHHxqZRD4mtYxuGG4ZrzUBEhPAlxHmDuGEx0rSG1YJhU3Yb7P QsFknjrMwsdm7zgaM4whxUT9dMxR32gjb/cRjYTk= 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-Google-Smtp-Source: AA0mqf6/e5CGGB2C0QBrtxUU1wdsh3owBRsimbV/E16HX7jp+bJEpAXw6c2kVwgTWR3BmhrFpvTtOA== 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 ()); +}