1 | /* Copyright JS Foundation and other contributors, http://js.foundation |
2 | * |
3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
4 | * you may not use this file except in compliance with the License. |
5 | * You may obtain a copy of the License at |
6 | * |
7 | * http://www.apache.org/licenses/LICENSE-2.0 |
8 | * |
9 | * Unless required by applicable law or agreed to in writing, software |
10 | * distributed under the License is distributed on an "AS IS" BASIS |
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | * See the License for the specific language governing permissions and |
13 | * limitations under the License. |
14 | */ |
15 | |
16 | #ifndef JERRYSCRIPT_COMPILER_H |
17 | #define JERRYSCRIPT_COMPILER_H |
18 | |
19 | #ifdef __cplusplus |
20 | extern "C" |
21 | { |
22 | #endif /* __cplusplus */ |
23 | |
24 | /** \addtogroup jerry-compiler Jerry compiler compatibility components |
25 | * @{ |
26 | */ |
27 | |
28 | #ifdef __GNUC__ |
29 | |
30 | /* |
31 | * Compiler-specific macros relevant for GCC. |
32 | */ |
33 | #define JERRY_ATTR_ALIGNED(ALIGNMENT) __attribute__((aligned(ALIGNMENT))) |
34 | #define JERRY_ATTR_ALWAYS_INLINE __attribute__((always_inline)) |
35 | #define JERRY_ATTR_CONST __attribute__((const)) |
36 | #define JERRY_ATTR_DEPRECATED __attribute__((deprecated)) |
37 | #define JERRY_ATTR_FORMAT(...) __attribute__((format(__VA_ARGS__))) |
38 | #define JERRY_ATTR_HOT __attribute__((hot)) |
39 | #define JERRY_ATTR_NOINLINE __attribute__((noinline)) |
40 | #define JERRY_ATTR_NORETURN __attribute__((noreturn)) |
41 | #define JERRY_ATTR_PURE __attribute__((pure)) |
42 | #define JERRY_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) |
43 | |
44 | #define JERRY_LIKELY(x) __builtin_expect(!!(x), 1) |
45 | #define JERRY_UNLIKELY(x) __builtin_expect(!!(x), 0) |
46 | |
47 | #endif /* __GNUC__ */ |
48 | |
49 | #ifdef _MSC_VER |
50 | |
51 | /* |
52 | * Compiler-specific macros relevant for Microsoft Visual C/C++ Compiler. |
53 | */ |
54 | #define JERRY_ATTR_DEPRECATED __declspec(deprecated) |
55 | #define JERRY_ATTR_NOINLINE __declspec(noinline) |
56 | #define JERRY_ATTR_NORETURN __declspec(noreturn) |
57 | |
58 | /* |
59 | * Microsoft Visual C/C++ Compiler doesn't support for VLA, using _alloca |
60 | * instead. |
61 | */ |
62 | void * __cdecl _alloca (size_t _Size); |
63 | #define JERRY_VLA(type, name, size) type *name = (type *) (_alloca (sizeof (type) * size)) |
64 | |
65 | #endif /* _MSC_VER */ |
66 | |
67 | /* |
68 | * Default empty definitions for all compiler-specific macros. Define any of |
69 | * these in a guarded block above (e.g., as for GCC) to fine tune compilation |
70 | * for your own compiler. */ |
71 | |
72 | /** |
73 | * Function attribute to align function to given number of bytes. |
74 | */ |
75 | #ifndef JERRY_ATTR_ALIGNED |
76 | #define JERRY_ATTR_ALIGNED(ALIGNMENT) |
77 | #endif /* !JERRY_ATTR_ALIGNED */ |
78 | |
79 | /** |
80 | * Function attribute to inline function to all call sites. |
81 | */ |
82 | #ifndef JERRY_ATTR_ALWAYS_INLINE |
83 | #define JERRY_ATTR_ALWAYS_INLINE |
84 | #endif /* !JERRY_ATTR_ALWAYS_INLINE */ |
85 | |
86 | /** |
87 | * Function attribute to declare that function has no effect except the return |
88 | * value and it only depends on parameters. |
89 | */ |
90 | #ifndef JERRY_ATTR_CONST |
91 | #define JERRY_ATTR_CONST |
92 | #endif /* !JERRY_ATTR_CONST */ |
93 | |
94 | /** |
95 | * Function attribute to trigger warning if deprecated function is called. |
96 | */ |
97 | #ifndef JERRY_ATTR_DEPRECATED |
98 | #define JERRY_ATTR_DEPRECATED |
99 | #endif /* !JERRY_ATTR_DEPRECATED */ |
100 | |
101 | /** |
102 | * Function attribute to declare that function is variadic and takes a format |
103 | * string and some arguments as parameters. |
104 | */ |
105 | #ifndef JERRY_ATTR_FORMAT |
106 | #define JERRY_ATTR_FORMAT(...) |
107 | #endif /* !JERRY_ATTR_FORMAT */ |
108 | |
109 | /** |
110 | * Function attribute to predict that function is a hot spot, and therefore |
111 | * should be optimized aggressively. |
112 | */ |
113 | #ifndef JERRY_ATTR_HOT |
114 | #define JERRY_ATTR_HOT |
115 | #endif /* !JERRY_ATTR_HOT */ |
116 | |
117 | /** |
118 | * Function attribute not to inline function ever. |
119 | */ |
120 | #ifndef JERRY_ATTR_NOINLINE |
121 | #define JERRY_ATTR_NOINLINE |
122 | #endif /* !JERRY_ATTR_NOINLINE */ |
123 | |
124 | /** |
125 | * Function attribute to declare that function never returns. |
126 | */ |
127 | #ifndef JERRY_ATTR_NORETURN |
128 | #define JERRY_ATTR_NORETURN |
129 | #endif /* !JERRY_ATTR_NORETURN */ |
130 | |
131 | /** |
132 | * Function attribute to declare that function has no effect except the return |
133 | * value and it only depends on parameters and global variables. |
134 | */ |
135 | #ifndef JERRY_ATTR_PURE |
136 | #define JERRY_ATTR_PURE |
137 | #endif /* !JERRY_ATTR_PURE */ |
138 | |
139 | /** |
140 | * Function attribute to trigger warning if function's caller doesn't use (e.g., |
141 | * check) the return value. |
142 | */ |
143 | #ifndef JERRY_ATTR_WARN_UNUSED_RESULT |
144 | #define JERRY_ATTR_WARN_UNUSED_RESULT |
145 | #endif /* !JERRY_ATTR_WARN_UNUSED_RESULT */ |
146 | |
147 | /** |
148 | * Helper to predict that a condition is likely. |
149 | */ |
150 | #ifndef JERRY_LIKELY |
151 | #define JERRY_LIKELY(x) (x) |
152 | #endif /* !JERRY_LIKELY */ |
153 | |
154 | /** |
155 | * Helper to predict that a condition is unlikely. |
156 | */ |
157 | #ifndef JERRY_UNLIKELY |
158 | #define JERRY_UNLIKELY(x) (x) |
159 | #endif /* !JERRY_UNLIKELY */ |
160 | |
161 | /** |
162 | * Helper to declare (or mimic) a C99 variable-length array. |
163 | */ |
164 | #ifndef JERRY_VLA |
165 | #define JERRY_VLA(type, name, size) type name[size] |
166 | #endif /* !JERRY_VLA */ |
167 | |
168 | /** |
169 | * @} |
170 | */ |
171 | |
172 | #ifdef __cplusplus |
173 | } |
174 | #endif /* __cplusplus */ |
175 | #endif /* !JERRYSCRIPT_COMPILER_H */ |
176 | |