From patchwork Mon Oct 10 15:31:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gaius Mulley X-Patchwork-Id: 1878 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1643329wrs; Mon, 10 Oct 2022 08:38:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4N1xJzxSe3BNVeLhEr/Fw4oT85CWsWRcaP0NisgP849nN0TZsJfMhXwXf8gsAB/KBy3EY6 X-Received: by 2002:a50:9510:0:b0:453:dded:60e with SMTP id u16-20020a509510000000b00453dded060emr18716736eda.204.1665416283737; Mon, 10 Oct 2022 08:38:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665416283; cv=none; d=google.com; s=arc-20160816; b=SNLIhH0iY4j+0EWSmrJ0/5zq843ufncuqhWqObXrWcYn01nyndFMUaEGOiEsnfSR04 /Y4YQXT5XUzBAozsazm112dTQSa5tEIbg5AvYZimsMkf+KdATV+4N1Iow1f/c26aoVKx WNeQ2oHnJZWuB500pNxQHOeC1Qiksvf/WC5TuGx4XXK9Cbx0bnNFqqTk+Iyau1R1roYp fMSfCALmRmxI/5PGdI0xcPosiwBjbbbOY/aJdzikSFzMVVwv4WlqblWQN+XruUvvkLwn gMzXMe4ies6lYjvDG8O93uZTRbkgtwMp5F1YTfbMhvu4Vq7JnSGfc3Oxpl9d8lpxu7vS CuQA== 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=PBe+OSZR1IeaPlcNJd6Dy+R+iQU3IGXnOphjQXycylI=; b=bsyYASduNSLtDMNm2ZoOnkTLnFUmsHrmX3qn/Qow1G3jQc8+xK5CnYrqL+7wdOGsHm 1u0clrGl+D34nf0zOD2sxXYp3BTfNHTcT9RTk8kbZR+NUUk+uJlFUN2bjrSNncZgueEA dtq0IrUCisciRuqadfBcHbsA0D7gDC7iKRUhinI64Ip4F8FQ/bQf2LOde2Pz3OX94geO iHWj2wRTn766F/hhPLI/CUNheJP0Uq5B7xxSCaJEKbLFpbxZpvwgIZlROf4KID/wpGxL uBlbF+TW634lZMA2W6A1uN084uCbo95y8eiEdndIvs45tV60T21OOQdgQnfNaRth6St5 gBHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=KAiyjCnC; 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 y22-20020a056402359600b0044900e60983si9973076edc.541.2022.10.10.08.38.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 08:38:03 -0700 (PDT) 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=KAiyjCnC; 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 2F554396DC0C for ; Mon, 10 Oct 2022 15:35:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F554396DC0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665416136; bh=PBe+OSZR1IeaPlcNJd6Dy+R+iQU3IGXnOphjQXycylI=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=KAiyjCnCnysCoHTEQf02uiHQwOTs42o9+jZAl8cx/oewwm4uYTKS7pcl65wqDr5dN rvPf4hkgneVlFWDwDLqlVe1Kx7ISkcUiRb70HCIGuLH+0owAhEQQkltiGobDcAqREj wkMwatjgo0YKoq+/wCQVGEutACZvFxYcym30wuaY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 015AC3948A5B for ; Mon, 10 Oct 2022 15:31:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 015AC3948A5B Received: by mail-wr1-x42f.google.com with SMTP id bu30so17568514wrb.8 for ; Mon, 10 Oct 2022 08:31:27 -0700 (PDT) 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=PBe+OSZR1IeaPlcNJd6Dy+R+iQU3IGXnOphjQXycylI=; b=zdfkMWa5GiYpBk8BYnJ/H1J4GYaZKN8g1ruY1EPz+b/X/qRneSX1n6g4i/HTd1rKMH I2NLJ1t93B67EX+XCD2YQY6agyicv2nJpcjhJUSf1xT4H/mjuod0I75ptpOSr9Su4joG a5L5KMQAO+BoTI9AH/KiHSOsd3UXV2TfRU2+9RXx0BIeZjnUOQieKwu54Z3/b2Wvokbt Co7/QE6lMYqWbE+83l/ju8WOtXesi3Ysuszoc+gjqjsuqF1BcOYLTdv/MetUWwz27ST7 Loo3cCpYdExjneY11/u3GnaXvBprNaq96XPHhMI/8KhYKhhvCFrqD6JEjwvy47ydyYuc +DWQ== X-Gm-Message-State: ACrzQf0PNW5RJ/zBtDO41DNBBZ/TTmL6O0TM3wVgcZdoy+pH4PcoPuw/ SYG7A5IQgBd1ILQWQFAfq5q1SuYK+34= X-Received: by 2002:adf:f98b:0:b0:22e:3694:a5e1 with SMTP id f11-20020adff98b000000b0022e3694a5e1mr12183429wrr.134.1665415886798; Mon, 10 Oct 2022 08:31:26 -0700 (PDT) Received: from lancelot ([195.147.220.46]) by smtp.gmail.com with ESMTPSA id s13-20020adfdb0d000000b002302dc43d77sm3746442wri.115.2022.10.10.08.31.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 08:31:26 -0700 (PDT) X-Google-Original-From: Gaius Mulley Received: from gaius by lancelot with local (Exim 4.94.2) (envelope-from ) id 1ohukW-00Bm3H-01 for gcc-patches@gcc.gnu.org; Mon, 10 Oct 2022 16:31:24 +0100 Subject: [PATCH] 13/19 modula2 front end: gimple interface *[g-m]*.cc To: X-Mailer: mail (GNU Mailutils 3.10) Message-Id: Date: Mon, 10 Oct 2022 16:31:24 +0100 X-Spam-Status: No, score=-1.4 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?1746315545385690856?= X-GMAIL-MSGID: =?utf-8?q?1746315545385690856?= 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-10-07 20:21:18.650096940 +0100 @@ -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-10-07 20:21:18.650096940 +0100 @@ -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 ()); +}