From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-wr1-x42f.google.com with SMTP id bu30so17568514wrb.8 for ; Mon, 10 Oct 2022 08:31:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:message-id:to:subject:from:from:to:cc:subject:date:message-id :reply-to; bh=PBe+OSZR1IeaPlcNJd6Dy+R+iQU3IGXnOphjQXycylI=; b=C997PlhtOEBfAQd1BYnQGEgYVEHF2p80go1M7RHE2HZHyfs6e+Fvx2Bz9t83v56A1o M/d5PQKww+zjvAldHsAb0IkwxXdnwYeKI1uygApuvNzKoC1hqEOUlupZOQnexH8WwqQy A5ubJhXfN83uPdKSQAKSAVb0fzQ1fupS6zBJqTbzElx+EMFDCEGdNxWeuAXfgqljfLgT iobsbIHr4DJdcGvlL48DSP5Olg7A5KfYe4TyFCKHWZiNlRidci7t1M5S7kwMiSUXVxQm G4R8kDs7r1Qi8bBZI9kypMGK1zOVn3uCXI4JHDqVxu0zD6klZWW/iKlfywZ71l1qfymA 8i7A== 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-Google-Smtp-Source: AMsMyM6MIAiCQeG8u86QNt+klwu29BF4moUMsBR5hi5ezvsC2ywezoBBKF+87/Wfl1Ka7lcZfEozlQ== 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) From: Gaius Mulley 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 List-Id: 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 ()); +}