borast: Win32: Comment #define in borast-compiler-private.h
[geda-pcb/pcjc2.git] / src / borast / borast-compiler-private.h
blob165b42ed43f51ea02d9c2ce5f4276e55586db164
1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2002 University of Southern California
4 * Copyright © 2005 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it either under the terms of the GNU Lesser General Public
8 * License version 2.1 as published by the Free Software Foundation
9 * (the "LGPL") or, at your option, under the terms of the Mozilla
10 * Public License Version 1.1 (the "MPL"). If you do not alter this
11 * notice, a recipient may use your version of this file under either
12 * the MPL or the LGPL.
14 * You should have received a copy of the LGPL along with this library
15 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * You should have received a copy of the MPL along with this library
18 * in the file COPYING-MPL-1.1
20 * The contents of this file are subject to the Mozilla Public License
21 * Version 1.1 (the "License"); you may not use this file except in
22 * compliance with the License. You may obtain a copy of the License at
23 * http://www.mozilla.org/MPL/
25 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27 * the specific language governing rights and limitations.
29 * The Original Code is the cairo graphics library.
31 * The Initial Developer of the Original Code is University of Southern
32 * California.
34 * Contributor(s):
35 * Carl D. Worth <cworth@cworth.org>
38 #ifndef BORAST_COMPILER_PRIVATE_H
39 #define BORAST_COMPILER_PRIVATE_H
41 #if HAVE_CONFIG_H
42 #include "config.h"
43 #endif
45 #if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun)
46 # define slim_hidden_proto(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) borast_private
47 # define slim_hidden_proto_no_warn(name) slim_hidden_proto1(name, slim_hidden_int_name(name)) borast_private_no_warn
48 # define slim_hidden_def(name) slim_hidden_def1(name, slim_hidden_int_name(name))
49 # define slim_hidden_int_name(name) INT_##name
50 # define slim_hidden_proto1(name, internal) \
51 extern __typeof (name) name \
52 __asm__ (slim_hidden_asmname (internal))
53 # define slim_hidden_def1(name, internal) \
54 extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name)) \
55 __attribute__((__alias__(slim_hidden_asmname(internal))))
56 # define slim_hidden_ulp slim_hidden_ulp1(__USER_LABEL_PREFIX__)
57 # define slim_hidden_ulp1(x) slim_hidden_ulp2(x)
58 # define slim_hidden_ulp2(x) #x
59 # define slim_hidden_asmname(name) slim_hidden_asmname1(name)
60 # define slim_hidden_asmname1(name) slim_hidden_ulp #name
61 #else
62 # define slim_hidden_proto(name) int _borast_dummy_prototype(void)
63 # define slim_hidden_proto_no_warn(name) int _borast_dummy_prototype(void)
64 # define slim_hidden_def(name) int _borast_dummy_prototype(void)
65 #endif
67 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
68 #define BORAST_PRINTF_FORMAT(fmt_index, va_index) \
69 __attribute__((__format__(__printf__, fmt_index, va_index)))
70 #else
71 #define BORAST_PRINTF_FORMAT(fmt_index, va_index)
72 #endif
74 /* slim_internal.h */
75 #define BORAST_HAS_HIDDEN_SYMBOLS 1
76 #if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
77 #define borast_private_no_warn __attribute__((__visibility__("hidden")))
78 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
79 #define borast_private_no_warn __hidden
80 #else /* not gcc >= 3.3 and not Sun Studio >= 8 */
81 #define borast_private_no_warn
82 #undef BORAST_HAS_HIDDEN_SYMBOLS
83 #endif
85 #ifndef WARN_UNUSED_RESULT
86 #define WARN_UNUSED_RESULT
87 #endif
88 /* Add attribute(warn_unused_result) if supported */
89 #define borast_warn WARN_UNUSED_RESULT
90 #define borast_private borast_private_no_warn borast_warn
92 /* This macro allow us to deprecate a function by providing an alias
93 for the old function name to the new function name. With this
94 macro, binary compatibility is preserved. The macro only works on
95 some platforms --- tough.
97 Meanwhile, new definitions in the public header file break the
98 source code so that it will no longer link against the old
99 symbols. Instead it will give a descriptive error message
100 indicating that the old function has been deprecated by the new
101 function.
103 #if __GNUC__ >= 2 && defined(__ELF__)
104 # define BORAST_FUNCTION_ALIAS(old, new) \
105 extern __typeof (new) old \
106 __asm__ ("" #old) \
107 __attribute__((__alias__("" #new)))
108 #else
109 # define BORAST_FUNCTION_ALIAS(old, new)
110 #endif
113 * Cairo uses the following function attributes in order to improve the
114 * generated code (effectively by manual inter-procedural analysis).
116 * 'borast_pure': The function is only allowed to read from its arguments
117 * and global memory (i.e. following a pointer argument or
118 * accessing a shared variable). The return value should
119 * only depend on its arguments, and for an identical set of
120 * arguments should return the same value.
122 * 'borast_const': The function is only allowed to read from its arguments.
123 * It is not allowed to access global memory. The return
124 * value should only depend its arguments, and for an
125 * identical set of arguments should return the same value.
126 * This is currently the most strict function attribute.
128 * Both these function attributes allow gcc to perform CSE and
129 * constant-folding, with 'borast_const 'also guaranteeing that pointer contents
130 * do not change across the function call.
132 #if __GNUC__ >= 3
133 #define borast_pure __attribute__((pure))
134 #define borast_const __attribute__((const))
135 #else
136 #define borast_pure
137 #define borast_const
138 #endif
140 #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
141 #define _BORAST_BOOLEAN_EXPR(expr) \
142 __extension__ ({ \
143 int _borast_boolean_var_; \
144 if (expr) \
145 _borast_boolean_var_ = 1; \
146 else \
147 _borast_boolean_var_ = 0; \
148 _borast_boolean_var_; \
150 #define likely(expr) (__builtin_expect (_BORAST_BOOLEAN_EXPR(expr), 1))
151 #define unlikely(expr) (__builtin_expect (_BORAST_BOOLEAN_EXPR(expr), 0))
152 #else
153 #define likely(expr) (expr)
154 #define unlikely(expr) (expr)
155 #endif
157 #ifndef __GNUC__
158 #undef __attribute__
159 #define __attribute__(x)
160 #endif
162 #if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER)
163 //#define snprintf _snprintf
164 #define popen _popen
165 #define pclose _pclose
166 #define hypot _hypot
167 #endif
169 #ifdef _MSC_VER
170 #undef inline
171 #define inline __inline
172 #endif
174 #if defined(_MSC_VER) && defined(_M_IX86)
175 /* When compiling with /Gy and /OPT:ICF identical functions will be folded in together.
176 The BORAST_ENSURE_UNIQUE macro ensures that a function is always unique and
177 will never be folded into another one. Something like this might eventually
178 be needed for GCC but it seems fine for now. */
179 #define BORAST_ENSURE_UNIQUE \
180 do { \
181 char func[] = __FUNCTION__; \
182 char file[] = __FILE__; \
183 __asm { \
184 __asm jmp __internal_skip_line_no \
185 __asm _emit (__LINE__ & 0xff) \
186 __asm _emit ((__LINE__>>8) & 0xff) \
187 __asm _emit ((__LINE__>>16) & 0xff) \
188 __asm _emit ((__LINE__>>24) & 0xff) \
189 __asm lea eax, func \
190 __asm lea eax, file \
191 __asm __internal_skip_line_no: \
192 }; \
193 } while (0)
194 #else
195 #define BORAST_ENSURE_UNIQUE do { } while (0)
196 #endif
198 #ifdef __STRICT_ANSI__
199 #undef inline
200 #define inline __inline__
201 #endif
203 #endif