When an object is a field in a union, it's the programmer's resposibility to destroy it from the union's destructor. We can simply neglect to do that and avoid having to use new to create the flags. Also, we can define the flags as inline variables (a c++17 feature), and then create a constexpr references to them. This lets us refer to debug flags in constexpr objects, although we can't interact with them at, for instance, construciton time or we'd lose our own constexpr-ness since the actual object is not constexpr. In c++20 we would hypothetically be able to use constexpr with new and delete, but there may be additional restrictions that would make this particular use impossible. Also this avoids leaking memory, which, even though it's intentional, may confuse tools like valgrind. Also, we need to ensure that all headers are included in some source file so that they exist in the final executable, so that they show up in the help, can be enabled/disabled, etc. Change-Id: Ia43111d938e7af7140b1c17dd68135f426d0a1e9 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/49783 Maintainer: Gabe Black <gabe.black@gmail.com> Reviewed-by: Jui-min Lee <fcrh@google.com> Tested-by: kokoro <noreply+kokoro@google.com>
51 lines
2.4 KiB
Python
51 lines
2.4 KiB
Python
# Copyright (c) 2018, 2020 ARM Limited
|
|
#
|
|
# The license below extends only to copyright in the software and shall
|
|
# not be construed as granting a license to any other intellectual
|
|
# property including but not limited to intellectual property relating
|
|
# to a hardware implementation of the functionality of the software
|
|
# licensed hereunder. You may use the software subject to the license
|
|
# terms below provided that you ensure that this notice is replicated
|
|
# unmodified and in its entirety in all distributions of the software,
|
|
# modified or unmodified, in source code or in binary form.
|
|
#
|
|
# Copyright (c) 2004-2005 The Regents of The University of Michigan
|
|
# All rights reserved.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without
|
|
# modification, are permitted provided that the following conditions are
|
|
# met: redistributions of source code must retain the above copyright
|
|
# notice, this list of conditions and the following disclaimer;
|
|
# redistributions in binary form must reproduce the above copyright
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
# documentation and/or other materials provided with the distribution;
|
|
# neither the name of the copyright holders nor the names of its
|
|
# contributors may be used to endorse or promote products derived from
|
|
# this software without specific prior written permission.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
import argparse
|
|
|
|
from code_formatter import code_formatter
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("cc", help="the path of the debug flag cc file")
|
|
parser.add_argument("name", help="the name of the debug flag")
|
|
|
|
args = parser.parse_args()
|
|
|
|
code = code_formatter()
|
|
code('#include "debug/${{args.name}}.hh"')
|
|
code.write(args.cc)
|