compiler.hh revision 9255
13938Ssaidi@eecs.umich.edu/* 23938Ssaidi@eecs.umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 33938Ssaidi@eecs.umich.edu * All rights reserved. 43938Ssaidi@eecs.umich.edu * 53938Ssaidi@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 63938Ssaidi@eecs.umich.edu * modification, are permitted provided that the following conditions are 73938Ssaidi@eecs.umich.edu * met: redistributions of source code must retain the above copyright 83938Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 93938Ssaidi@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 103938Ssaidi@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 113938Ssaidi@eecs.umich.edu * documentation and/or other materials provided with the distribution; 123938Ssaidi@eecs.umich.edu * neither the name of the copyright holders nor the names of its 133938Ssaidi@eecs.umich.edu * contributors may be used to endorse or promote products derived from 143938Ssaidi@eecs.umich.edu * this software without specific prior written permission. 153938Ssaidi@eecs.umich.edu * 163938Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173938Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183938Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193938Ssaidi@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203938Ssaidi@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213938Ssaidi@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223938Ssaidi@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233938Ssaidi@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243938Ssaidi@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253938Ssaidi@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263938Ssaidi@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273938Ssaidi@eecs.umich.edu * 283938Ssaidi@eecs.umich.edu * Authors: Ali Saidi 293938Ssaidi@eecs.umich.edu */ 303938Ssaidi@eecs.umich.edu 313938Ssaidi@eecs.umich.edu#ifndef __BASE_COMPILER_HH__ 323938Ssaidi@eecs.umich.edu#define __BASE_COMPILER_HH__ 333938Ssaidi@eecs.umich.edu 349255SAndreas.Sandberg@arm.com#include "config/have_static_assert.hh" 359255SAndreas.Sandberg@arm.com 363938Ssaidi@eecs.umich.edu//http://msdn2.microsoft.com/en-us/library/ms937669.aspx 373938Ssaidi@eecs.umich.edu//http://msdn2.microsoft.com/en-us/library/aa448724.aspx 383938Ssaidi@eecs.umich.edu//http://docs.sun.com/source/819-3688/sun.specific.html#marker-998278 393938Ssaidi@eecs.umich.edu//http://gcc.gnu.org/onlinedocs/gcc-3.3.1/gcc/Function-Attributes.html#Function%20Attributes 403938Ssaidi@eecs.umich.edu 413938Ssaidi@eecs.umich.edu#if defined(__GNUC__) 423938Ssaidi@eecs.umich.edu#define M5_ATTR_NORETURN __attribute__((noreturn)) 433938Ssaidi@eecs.umich.edu#define M5_PRAGMA_NORETURN(x) 443938Ssaidi@eecs.umich.edu#define M5_DUMMY_RETURN 454964Ssaidi@eecs.umich.edu#define M5_VAR_USED __attribute__((unused)) 467949SAli.Saidi@ARM.com#define M5_ATTR_PACKED __attribute__ ((__packed__)) 478620Sgblack@eecs.umich.edu#define M5_NO_INLINE __attribute__ ((__noinline__)) 483938Ssaidi@eecs.umich.edu#elif defined(__SUNPRO_CC) 493938Ssaidi@eecs.umich.edu// this doesn't do anything with sun cc, but why not 503938Ssaidi@eecs.umich.edu#define M5_ATTR_NORETURN __sun_attr__((__noreturn__)) 513938Ssaidi@eecs.umich.edu#define M5_DUMMY_RETURN return (0); 523940Ssaidi@eecs.umich.edu#define DO_PRAGMA(x) _Pragma(#x) 534964Ssaidi@eecs.umich.edu#define M5_VAR_USED 543940Ssaidi@eecs.umich.edu#define M5_PRAGMA_NORETURN(x) DO_PRAGMA(does_not_return(x)) 557949SAli.Saidi@ARM.com#define M5_ATTR_PACKED __attribute__ ((__packed__)) 568620Sgblack@eecs.umich.edu#define M5_NO_INLINE __attribute__ ((__noinline__)) 573938Ssaidi@eecs.umich.edu#else 583938Ssaidi@eecs.umich.edu#error "Need to define compiler options in base/compiler.hh" 593938Ssaidi@eecs.umich.edu#endif 603938Ssaidi@eecs.umich.edu 619255SAndreas.Sandberg@arm.com/* 629255SAndreas.Sandberg@arm.com * Define a compatibility macro that emulates the behavior of 639255SAndreas.Sandberg@arm.com * static_assert using template magic if the compiler doesn't have 649255SAndreas.Sandberg@arm.com * native support. 659255SAndreas.Sandberg@arm.com */ 669255SAndreas.Sandberg@arm.com#if !HAVE_STATIC_ASSERT 679255SAndreas.Sandberg@arm.com 689255SAndreas.Sandberg@arm.comtemplate<bool> 699255SAndreas.Sandberg@arm.comstruct static_assert_failure; 709255SAndreas.Sandberg@arm.com 719255SAndreas.Sandberg@arm.comtemplate<> 729255SAndreas.Sandberg@arm.comstruct static_assert_failure<false> {}; 739255SAndreas.Sandberg@arm.com 749255SAndreas.Sandberg@arm.com/* The following macro causes the compiler to evaluate the size of the 759255SAndreas.Sandberg@arm.com * static_assert_failure struct. The templates are designed so that 769255SAndreas.Sandberg@arm.com * only static_assert_failure<false> evaluates to a proper size, while 779255SAndreas.Sandberg@arm.com * static_assert_failure<true> generates a compile time error. 789255SAndreas.Sandberg@arm.com */ 799255SAndreas.Sandberg@arm.com#define static_assert(expr, msg) \ 809255SAndreas.Sandberg@arm.com namespace ns_static_assert { \ 819255SAndreas.Sandberg@arm.com enum { \ 829255SAndreas.Sandberg@arm.com static_assert_ ## __LINE__ = \ 839255SAndreas.Sandberg@arm.com sizeof(static_assert_failure<!(expr)>) \ 849255SAndreas.Sandberg@arm.com }; \ 859255SAndreas.Sandberg@arm.com } 869255SAndreas.Sandberg@arm.com 879255SAndreas.Sandberg@arm.com#endif 889255SAndreas.Sandberg@arm.com 893938Ssaidi@eecs.umich.edu#endif // __BASE_COMPILER_HH__ 90