SimpleOpts.py revision 11104
12SN/A# -*- coding: utf-8 -*-
21762SN/A# Copyright (c) 2015 Jason Power
32SN/A# All rights reserved.
42SN/A#
52SN/A# Redistribution and use in source and binary forms, with or without
62SN/A# modification, are permitted provided that the following conditions are
72SN/A# met: redistributions of source code must retain the above copyright
82SN/A# notice, this list of conditions and the following disclaimer;
92SN/A# redistributions in binary form must reproduce the above copyright
102SN/A# notice, this list of conditions and the following disclaimer in the
112SN/A# documentation and/or other materials provided with the distribution;
122SN/A# neither the name of the copyright holders nor the names of its
132SN/A# contributors may be used to endorse or promote products derived from
142SN/A# this software without specific prior written permission.
152SN/A#
162SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu#
282665Ssaidi@eecs.umich.edu# Authors: Jason Power
292665Ssaidi@eecs.umich.edu
302SN/A""" Options wrapper for simple gem5 configuration scripts
312SN/A
321388SN/AThis module wraps the optparse class so that we can register options
332SN/Afrom each class instead of only from the configuration script.
342SN/A
352SN/A"""
361191SN/A
371191SN/A# Module-level variable to track if we've called the parse_args function yet
381191SN/Acalled_parse_args = False
391388SN/A
405529Snate@binkert.org# For fatal
411717SN/Aimport m5
422651Ssaidi@eecs.umich.edu
432680Sktlim@umich.edu# import the options parser
441977SN/Afrom optparse import OptionParser
455529Snate@binkert.org
463144Shsul@eecs.umich.edu# add the options we want to be able to control from the command line
472190SN/Aparser = OptionParser()
4856SN/A
492190SN/Adef add_option(*args, **kwargs):
502SN/A    """Call "add_option" to the global options parser
512359SN/A    """
522359SN/A
532359SN/A    if (parser.has_option(args[0]) or
542SN/A            (len(args) > 1 and parser.has_option(args[1])) ):
552SN/A        m5.fatal("Duplicate option: %s" % str(args))
562SN/A
572SN/A    if called_parse_args:
582SN/A        m5.fatal("Can't add an option after calling SimpleOpts.parse_args")
592SN/A
602SN/A    parser.add_option(*args, **kwargs)
612SN/A
622SN/Adef parse_args():
635606Snate@binkert.org    global called_parse_args
645606Snate@binkert.org    called_parse_args = True
655606Snate@binkert.org
663126Sktlim@umich.edu    return parser.parse_args()
673126Sktlim@umich.edu
685606Snate@binkert.orgdef set_usage(*args, **kwargs):
693126Sktlim@umich.edu    parser.set_usage(*args, **kwargs)
703126Sktlim@umich.edu
712356SN/Adef print_help(*args, **kwargs):
722356SN/A    parser.print_help(*args, **kwargs)
732356SN/A
742367SN/A