Verified Commit 503cd4b2 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Add C++17 transformer for Hermes output

parent 3c9e0e3b
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
# Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain
#
# This software was partially supported by the EuroHPC-funded project ADMIRE
#   (Project ID: 956748, https://www.admire-eurohpc.eu).
#
# This file is part of rpcc.
#
# rpcc 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 of the License, or (at your option) any later version.
#
# rpcc 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 Lesser General Public License along with rpcc.  If not, see
# <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later


from .rpcc import Rpcc
+35 −8
Original line number Diff line number Diff line
import sys

import lark.exceptions
# Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain
#
# This software was partially supported by the EuroHPC-funded project ADMIRE
#   (Project ID: 956748, https://www.admire-eurohpc.eu).
#
# This file is part of rpcc.
#
# rpcc 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 of the License, or (at your option) any later version.
#
# rpcc 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 Lesser General Public License along with rpcc.  If not, see
# <https://www.gnu.org/licenses/>.
#
#  SPDX-License-Identifier: GPL-3.0-or-later

import sys
from rpcc import Rpcc
from rpcc.arguments import parse_args
from rpcc.exceptions import RpccError
from rpcc.exceptions import RpccSyntaxError
from rpcc.console import console
from loguru import logger


def main(args=None):
@@ -15,13 +31,24 @@ def main(args=None):
        args = sys.argv[1:]

    args = parse_args(args)

    # configure console
    console.configure(args.color_diagnostics)

    rpcc = Rpcc(args.rpc_proto_file, args.output_lang)
    # configure logging
    logger.remove()
    logger.add(sys.stderr, level=args.loglevel)

    try:
        rpcc.transform()
    except RpccError as e:
        console.eprint(e)
        Rpcc(
            args.rpc_proto_file,
            args.copyright_file,
            args.output_lang,
            args.header_output_dir,
            args.impl_output_dir
        ).transform()
    except (RpccSyntaxError, OSError) as e:
        console.eprint(f"ERROR: {e}")
        return 1

    return 0
+105 −2
Original line number Diff line number Diff line
# Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain
#
# This software was partially supported by the EuroHPC-funded project ADMIRE
#   (Project ID: 956748, https://www.admire-eurohpc.eu).
#
# This file is part of rpcc.
#
# rpcc 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 of the License, or (at your option) any later version.
#
# rpcc 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 Lesser General Public License along with rpcc.  If not, see
# <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

import argparse
import logging
import sys
from pathlib import Path
from rpcc.version import __version__ as rpcc_version
from rpcc.console import console


class PrintVersion(argparse.Action):
class _SetVerbosity(argparse.Action):
    def __init__(self, option_strings, dest, const=None, default=None,
                 required=False, help=None, metavar=None):
        super().__init__(option_strings=option_strings,
                         dest=dest,
                         nargs=0,
                         const=const,
                         default=default,
                         required=required,
                         help=help)

        self.count = 0

    def __call__(self, parser, namespace, values, option_string=None):
        levels = [
            logging.CRITICAL,
            logging.ERROR,
            logging.WARNING,
            25,  # LOGURU_SUCCESS_NO
            logging.INFO,
            logging.DEBUG,
            5  # LOGURU_TRACE_NO
        ]

        setattr(namespace, self.dest, levels[self.count])
        self.count = min(self.count + 1, len(levels) - 1)


class _PrintVersion(argparse.Action):
    def __init__(self, option_strings, dest, const=None, default=None,
                 required=False, help=None, metavar=None):
        super().__init__(option_strings=option_strings,
@@ -33,6 +80,18 @@ def parse_args(args) -> argparse.Namespace:
        help="The file containing the specifications for the RPCs."
    )

    parser.add_argument(
        "--output-mode",
        choices=["hermes"],
        dest="output_mode",
        metavar="LIBRARY",
        default="hermes",
        help="Set the output mode. Possible values for LIBRARY are:\n"
             "\n"
             "hermes\n"
             "    Generate code that can be used with the Hermes library."
    )

    parser.add_argument(
        "--std",
        choices=["c++17"],
@@ -45,6 +104,31 @@ def parse_args(args) -> argparse.Namespace:
             "    2017 ISO C++ standard."
    )

    parser.add_argument(
        "--c_out",
        type=Path,
        metavar="OUT_DIR",
        dest="impl_output_dir",
        help="The directory where C/C++ implementation files should be generated.",
        default=Path.cwd()
    )

    parser.add_argument(
        "--h_out",
        type=Path,
        metavar="OUT_DIR",
        dest="header_output_dir",
        help="The directory where C/C++ header files should be generated.",
        default=Path.cwd()
    )

    parser.add_argument(
        "--copyright-file",
        type=Path,
        default=None,
        help="Use the text in COPYRIGHT_FILE as the copyright header of all generated files."
    )

    parser.add_argument(
        "--color-diagnostics",
        choices=["never", "always", "auto"],
@@ -54,10 +138,29 @@ def parse_args(args) -> argparse.Namespace:
             "always, or auto (the default)."
    )

    parser.add_argument(
        "--debug",
        "-d",
        action="store_const",
        dest="loglevel",
        const=logging.DEBUG,
        default=logging.WARNING,
        help=argparse.SUPPRESS
    )

    parser.add_argument(
        "--verbose",
        "-v",
        action=_SetVerbosity,
        dest="loglevel",
        default=logging.INFO,
        help="Increase verbosity"
    )

    parser.add_argument(
        "--version",
        "-V",
        action=PrintVersion,
        action=_PrintVersion,
        help="Display rpcc version information."
    )

+18 −0
Original line number Diff line number Diff line
# Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain
#
# This software was partially supported by the EuroHPC-funded project ADMIRE
#   (Project ID: 956748, https://www.admire-eurohpc.eu).
#
# This file is part of rpcc.
#
# rpcc 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 of the License, or (at your option) any later version.
#
# rpcc 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 Lesser General Public License along with rpcc.  If not, see
# <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

from typing import Any

from rich.console import Console as RichConsole
+18 −0
Original line number Diff line number Diff line
# Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain
#
# This software was partially supported by the EuroHPC-funded project ADMIRE
#   (Project ID: 956748, https://www.admire-eurohpc.eu).
#
# This file is part of rpcc.
#
# rpcc 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 of the License, or (at your option) any later version.
#
# rpcc 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 Lesser General Public License along with rpcc.  If not, see
# <https://www.gnu.org/licenses/>.
#
# SPDX-License-Identifier: GPL-3.0-or-later

from rich.highlighter import RegexHighlighter


Loading