SimpleOpts.py revision 11104
12155SN/A# -*- coding: utf-8 -*-
22155SN/A# Copyright (c) 2015 Jason Power
32155SN/A# All rights reserved.
42155SN/A#
52155SN/A# Redistribution and use in source and binary forms, with or without
62155SN/A# modification, are permitted provided that the following conditions are
72155SN/A# met: redistributions of source code must retain the above copyright
82155SN/A# notice, this list of conditions and the following disclaimer;
92155SN/A# redistributions in binary form must reproduce the above copyright
102155SN/A# notice, this list of conditions and the following disclaimer in the
112155SN/A# documentation and/or other materials provided with the distribution;
122155SN/A# neither the name of the copyright holders nor the names of its
132155SN/A# contributors may be used to endorse or promote products derived from
142155SN/A# this software without specific prior written permission.
152155SN/A#
162155SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172155SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182155SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192155SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202155SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212155SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222155SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232155SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242155SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252155SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262155SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272155SN/A#
282665Ssaidi@eecs.umich.edu# Authors: Jason Power
292665Ssaidi@eecs.umich.edu
302155SN/A""" Options wrapper for simple gem5 configuration scripts
312155SN/A
322155SN/AThis module wraps the optparse class so that we can register options
332155SN/Afrom each class instead of only from the configuration script.
342155SN/A
352155SN/A"""
362155SN/A
372178SN/A# Module-level variable to track if we've called the parse_args function yet
382178SN/Acalled_parse_args = False
392178SN/A
402178SN/A# For fatal
412178SN/Aimport m5
422178SN/A
432178SN/A# import the options parser
442178SN/Afrom optparse import OptionParser
452178SN/A
462178SN/A# add the options we want to be able to control from the command line
472178SN/Aparser = OptionParser()
482178SN/A
492155SN/Adef add_option(*args, **kwargs):
502178SN/A    """Call "add_option" to the global options parser
512155SN/A    """
522155SN/A
532178SN/A    if (parser.has_option(args[0]) or
542155SN/A            (len(args) > 1 and parser.has_option(args[1])) ):
552155SN/A        m5.fatal("Duplicate option: %s" % str(args))
562623SN/A
572623SN/A    if called_parse_args:
582623SN/A        m5.fatal("Can't add an option after calling SimpleOpts.parse_args")
592623SN/A
602623SN/A    parser.add_option(*args, **kwargs)
612155SN/A
622155SN/Adef parse_args():
632292SN/A    global called_parse_args
642292SN/A    called_parse_args = True
652292SN/A
662292SN/A    return parser.parse_args()
672292SN/A
682292SN/Adef set_usage(*args, **kwargs):
692292SN/A    parser.set_usage(*args, **kwargs)
702292SN/A
712766Sktlim@umich.edudef print_help(*args, **kwargs):
722766Sktlim@umich.edu    parser.print_help(*args, **kwargs)
732766Sktlim@umich.edu
742766Sktlim@umich.edu