111104Spower.jg@gmail.com# -*- coding: utf-8 -*-
211104Spower.jg@gmail.com# Copyright (c) 2015 Jason Power
311104Spower.jg@gmail.com# All rights reserved.
411104Spower.jg@gmail.com#
511104Spower.jg@gmail.com# Redistribution and use in source and binary forms, with or without
611104Spower.jg@gmail.com# modification, are permitted provided that the following conditions are
711104Spower.jg@gmail.com# met: redistributions of source code must retain the above copyright
811104Spower.jg@gmail.com# notice, this list of conditions and the following disclaimer;
911104Spower.jg@gmail.com# redistributions in binary form must reproduce the above copyright
1011104Spower.jg@gmail.com# notice, this list of conditions and the following disclaimer in the
1111104Spower.jg@gmail.com# documentation and/or other materials provided with the distribution;
1211104Spower.jg@gmail.com# neither the name of the copyright holders nor the names of its
1311104Spower.jg@gmail.com# contributors may be used to endorse or promote products derived from
1411104Spower.jg@gmail.com# this software without specific prior written permission.
1511104Spower.jg@gmail.com#
1611104Spower.jg@gmail.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1711104Spower.jg@gmail.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1811104Spower.jg@gmail.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1911104Spower.jg@gmail.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2011104Spower.jg@gmail.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2111104Spower.jg@gmail.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2211104Spower.jg@gmail.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2311104Spower.jg@gmail.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2411104Spower.jg@gmail.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2511104Spower.jg@gmail.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2611104Spower.jg@gmail.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711104Spower.jg@gmail.com#
2811104Spower.jg@gmail.com# Authors: Jason Power
2911104Spower.jg@gmail.com
3013774Sandreas.sandberg@arm.comfrom __future__ import print_function
3113774Sandreas.sandberg@arm.comfrom __future__ import absolute_import
3213774Sandreas.sandberg@arm.com
3311104Spower.jg@gmail.com""" Options wrapper for simple gem5 configuration scripts
3411104Spower.jg@gmail.com
3511104Spower.jg@gmail.comThis module wraps the optparse class so that we can register options
3611104Spower.jg@gmail.comfrom each class instead of only from the configuration script.
3711104Spower.jg@gmail.com
3811104Spower.jg@gmail.com"""
3911104Spower.jg@gmail.com
4011104Spower.jg@gmail.com# Module-level variable to track if we've called the parse_args function yet
4111104Spower.jg@gmail.comcalled_parse_args = False
4211104Spower.jg@gmail.com
4311104Spower.jg@gmail.com# For fatal
4411104Spower.jg@gmail.comimport m5
4511104Spower.jg@gmail.com
4611104Spower.jg@gmail.com# import the options parser
4711104Spower.jg@gmail.comfrom optparse import OptionParser
4811104Spower.jg@gmail.com
4911104Spower.jg@gmail.com# add the options we want to be able to control from the command line
5011104Spower.jg@gmail.comparser = OptionParser()
5111104Spower.jg@gmail.com
5211104Spower.jg@gmail.comdef add_option(*args, **kwargs):
5311104Spower.jg@gmail.com    """Call "add_option" to the global options parser
5411104Spower.jg@gmail.com    """
5511104Spower.jg@gmail.com
5611104Spower.jg@gmail.com    if (parser.has_option(args[0]) or
5711104Spower.jg@gmail.com            (len(args) > 1 and parser.has_option(args[1])) ):
5811104Spower.jg@gmail.com        m5.fatal("Duplicate option: %s" % str(args))
5911104Spower.jg@gmail.com
6011104Spower.jg@gmail.com    if called_parse_args:
6111104Spower.jg@gmail.com        m5.fatal("Can't add an option after calling SimpleOpts.parse_args")
6211104Spower.jg@gmail.com
6311104Spower.jg@gmail.com    parser.add_option(*args, **kwargs)
6411104Spower.jg@gmail.com
6511104Spower.jg@gmail.comdef parse_args():
6611104Spower.jg@gmail.com    global called_parse_args
6711104Spower.jg@gmail.com    called_parse_args = True
6811104Spower.jg@gmail.com
6911104Spower.jg@gmail.com    return parser.parse_args()
7011104Spower.jg@gmail.com
7111104Spower.jg@gmail.comdef set_usage(*args, **kwargs):
7211104Spower.jg@gmail.com    parser.set_usage(*args, **kwargs)
7311104Spower.jg@gmail.com
7411104Spower.jg@gmail.comdef print_help(*args, **kwargs):
7511104Spower.jg@gmail.com    parser.print_help(*args, **kwargs)
7611104Spower.jg@gmail.com
77