13938Ssaidi@eecs.umich.edu/*
212701Snikos.nikoleris@arm.com * Copyright (c) 2012,2017-2018 ARM Limited
39419Sandreas.hansson@arm.com * All rights reserved
49419Sandreas.hansson@arm.com *
59419Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
69419Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
79419Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
89419Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
99419Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
109419Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
119419Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
129419Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
139419Sandreas.hansson@arm.com *
143938Ssaidi@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan
153938Ssaidi@eecs.umich.edu * All rights reserved.
163938Ssaidi@eecs.umich.edu *
173938Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
183938Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are
193938Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright
203938Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
213938Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
223938Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
233938Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution;
243938Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its
253938Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from
263938Ssaidi@eecs.umich.edu * this software without specific prior written permission.
273938Ssaidi@eecs.umich.edu *
283938Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
293938Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
303938Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
313938Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
323938Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
333938Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
343938Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
353938Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
363938Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
373938Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
383938Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
393938Ssaidi@eecs.umich.edu *
403938Ssaidi@eecs.umich.edu * Authors: Ali Saidi
413938Ssaidi@eecs.umich.edu */
423938Ssaidi@eecs.umich.edu
433938Ssaidi@eecs.umich.edu#ifndef __BASE_COMPILER_HH__
443938Ssaidi@eecs.umich.edu#define __BASE_COMPILER_HH__
453938Ssaidi@eecs.umich.edu
4612225Sgiacomo.travaglini@arm.com#include <memory>
4712225Sgiacomo.travaglini@arm.com
489419Sandreas.hansson@arm.com// http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
493938Ssaidi@eecs.umich.edu
5010291SAndreas.Sandberg@ARM.com#if defined(__GNUC__) // clang or gcc
5110291SAndreas.Sandberg@ARM.com#  define M5_ATTR_NORETURN  __attribute__((noreturn))
5210291SAndreas.Sandberg@ARM.com#  define M5_DUMMY_RETURN
5310291SAndreas.Sandberg@ARM.com#  define M5_VAR_USED __attribute__((unused))
5410291SAndreas.Sandberg@ARM.com#  define M5_ATTR_PACKED __attribute__ ((__packed__))
5510291SAndreas.Sandberg@ARM.com#  define M5_NO_INLINE __attribute__ ((__noinline__))
5610686SAndreas.Sandberg@ARM.com#  define M5_DEPRECATED __attribute__((deprecated))
5710686SAndreas.Sandberg@ARM.com#  define M5_DEPRECATED_MSG(MSG) __attribute__((deprecated(MSG)))
5812595Ssiddhesh.poyarekar@gmail.com#  define M5_UNREACHABLE __builtin_unreachable()
5912806Sandreas.sandberg@arm.com#  define M5_PUBLIC __attribute__ ((visibility ("default")))
6012806Sandreas.sandberg@arm.com#  define M5_LOCAL __attribute__ ((visibility ("hidden")))
6110291SAndreas.Sandberg@ARM.com#endif
6210104Smitch.hayenga@arm.com
6310104Smitch.hayenga@arm.com#if defined(__clang__)
6410291SAndreas.Sandberg@ARM.com#  define M5_CLASS_VAR_USED M5_VAR_USED
6510104Smitch.hayenga@arm.com#else
6610291SAndreas.Sandberg@ARM.com#  define M5_CLASS_VAR_USED
673938Ssaidi@eecs.umich.edu#endif
683938Ssaidi@eecs.umich.edu
6912392Sjason@lowepower.com// This can be removed once all compilers support C++17
7012392Sjason@lowepower.com#if defined __has_cpp_attribute
7112392Sjason@lowepower.com    // Note: We must separate this if statement because GCC < 5.0 doesn't
7212392Sjason@lowepower.com    //       support the function-like syntax in #if statements.
7312392Sjason@lowepower.com    #if __has_cpp_attribute(fallthrough)
7412392Sjason@lowepower.com        #define M5_FALLTHROUGH [[fallthrough]]
7512392Sjason@lowepower.com    #else
7612392Sjason@lowepower.com        #define M5_FALLTHROUGH
7712392Sjason@lowepower.com    #endif
7812701Snikos.nikoleris@arm.com
7912701Snikos.nikoleris@arm.com    #if __has_cpp_attribute(nodiscard)
8012701Snikos.nikoleris@arm.com        #define M5_NODISCARD [[nodiscard]]
8112701Snikos.nikoleris@arm.com    #else
8212701Snikos.nikoleris@arm.com        #define M5_NODISCARD
8312701Snikos.nikoleris@arm.com    #endif
8412392Sjason@lowepower.com#else
8512392Sjason@lowepower.com    // Unsupported (and no warning) on GCC < 7.
8612392Sjason@lowepower.com    #define M5_FALLTHROUGH
8712701Snikos.nikoleris@arm.com
8812701Snikos.nikoleris@arm.com    #define M5_NODISCARD
8912392Sjason@lowepower.com#endif
9012392Sjason@lowepower.com
9112225Sgiacomo.travaglini@arm.com// std::make_unique redefined for C++11 compilers
9212225Sgiacomo.travaglini@arm.comnamespace m5
9312225Sgiacomo.travaglini@arm.com{
9412225Sgiacomo.travaglini@arm.com
9512859Sanimalvgamer@gmail.com#if __cplusplus >= 201402L // C++14
9612225Sgiacomo.travaglini@arm.com
9712225Sgiacomo.travaglini@arm.comusing std::make_unique;
9812225Sgiacomo.travaglini@arm.com
9912225Sgiacomo.travaglini@arm.com#else // C++11
10012225Sgiacomo.travaglini@arm.com
10112225Sgiacomo.travaglini@arm.com/** Defining custom version of make_unique: m5::make_unique<>() */
10212225Sgiacomo.travaglini@arm.comtemplate<typename T, typename... Args>
10312225Sgiacomo.travaglini@arm.comstd::unique_ptr<T>
10412225Sgiacomo.travaglini@arm.commake_unique( Args&&... constructor_args )
10512225Sgiacomo.travaglini@arm.com{
10612225Sgiacomo.travaglini@arm.com    return std::unique_ptr<T>(
10712225Sgiacomo.travaglini@arm.com               new T( std::forward<Args>(constructor_args)... )
10812225Sgiacomo.travaglini@arm.com           );
10912225Sgiacomo.travaglini@arm.com}
11012225Sgiacomo.travaglini@arm.com
11112859Sanimalvgamer@gmail.com#endif // __cplusplus >= 201402L
11212225Sgiacomo.travaglini@arm.com
11312225Sgiacomo.travaglini@arm.com} //namespace m5
11412225Sgiacomo.travaglini@arm.com
1153938Ssaidi@eecs.umich.edu#endif // __BASE_COMPILER_HH__
116