|
| 1 | +# Copyright 2024 (c) Jason Lowe-Power |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# Redistribution and use in source and binary forms, with or without |
| 5 | +# modification, are permitted provided that the following conditions are |
| 6 | +# met: redistributions of source code must retain the above copyright |
| 7 | +# notice, this list of conditions and the following disclaimer; |
| 8 | +# redistributions in binary form must reproduce the above copyright |
| 9 | +# notice, this list of conditions and the following disclaimer in the |
| 10 | +# documentation and/or other materials provided with the distribution; |
| 11 | +# neither the name of the copyright holders nor the names of its |
| 12 | +# contributors may be used to endorse or promote products derived from |
| 13 | +# this software without specific prior written permission. |
| 14 | +# |
| 15 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 18 | +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 19 | +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 21 | +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | + |
| 27 | +import importlib |
| 28 | + |
| 29 | +from m5.defines import buildEnv |
| 30 | + |
| 31 | + |
| 32 | +def define_options(parser): |
| 33 | + print("**************IMPORTANT*******************************") |
| 34 | + print("This gem5 binary is configured with multiple protocols.") |
| 35 | + print("To use this gem5 binary, you must use the standard library.") |
| 36 | + print("The Ruby.py file is deprecated.") |
| 37 | + print("You can use --protocol to specify the protocol you want to use.") |
| 38 | + print("IMPORTANT: THIS WILL BE REMOVED IN THE FUTURE.") |
| 39 | + |
| 40 | + available_protocols = [ |
| 41 | + protocol[len("RUBY_PROTOCOL_") :] |
| 42 | + for protocol in buildEnv.keys() |
| 43 | + if protocol.startswith("RUBY_PROTOCOL_") |
| 44 | + ] |
| 45 | + |
| 46 | + parser.add_argument( |
| 47 | + "--protocol", |
| 48 | + type=str, |
| 49 | + help="Specify the protocol you want to use.", |
| 50 | + required=True, |
| 51 | + choices=available_protocols, |
| 52 | + ) |
| 53 | + |
| 54 | + # Note: we can't rely on the options yet because they haven't been parsed. |
| 55 | + from sys import argv |
| 56 | + |
| 57 | + found = False |
| 58 | + for arg in argv: |
| 59 | + if arg.startswith("--protocol"): |
| 60 | + found = True |
| 61 | + if "=" in arg: |
| 62 | + protocol = arg[len("--protocol=") :] |
| 63 | + else: |
| 64 | + protocol = argv[argv.index(arg) + 1] |
| 65 | + if not found: |
| 66 | + print( |
| 67 | + "ERROR: You must specify a protocol with --protocol <protocol>. " |
| 68 | + "or --protocol=<protocol>" |
| 69 | + ) |
| 70 | + exit(1) |
| 71 | + |
| 72 | + protocol_module = importlib.import_module(f".{protocol}", package="ruby") |
| 73 | + protocol_module.define_options(parser) |
| 74 | + buildEnv["PROTOCOL"] = protocol |
| 75 | + |
| 76 | + |
| 77 | +# Note: This function isn't used because buildEnv["PROTOCOL"] is set |
| 78 | +# in define_options. However, this is here just in case. |
| 79 | +def create_system(options, *args, **kwargs): |
| 80 | + protocol = options.protocol |
| 81 | + print("Using protocol: ", protocol) |
| 82 | + print("WARNING: The Ruby.py file is deprecated.") |
| 83 | + |
| 84 | + protocol_module = importlib.import_module(f".{protocol}", package="ruby") |
| 85 | + (cpu_sequencers, dir_cntrls, topology) = protocol_module.create_system( |
| 86 | + options, *args, **kwargs |
| 87 | + ) |
| 88 | + |
| 89 | + return (cpu_sequencers, dir_cntrls, topology) |
0 commit comments