1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci *
3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci * You may obtain a copy of the License at
6425bb815Sopenharmony_ci *
7425bb815Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci *
9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci * limitations under the License.
14425bb815Sopenharmony_ci */
15425bb815Sopenharmony_ci
16425bb815Sopenharmony_ci#ifndef JERRYSCRIPT_COMPILER_H
17425bb815Sopenharmony_ci#define JERRYSCRIPT_COMPILER_H
18425bb815Sopenharmony_ci
19425bb815Sopenharmony_ci#ifdef __cplusplus
20425bb815Sopenharmony_ciextern "C"
21425bb815Sopenharmony_ci{
22425bb815Sopenharmony_ci#endif /* __cplusplus */
23425bb815Sopenharmony_ci
24425bb815Sopenharmony_ci/** \addtogroup jerry-compiler Jerry compiler compatibility components
25425bb815Sopenharmony_ci * @{
26425bb815Sopenharmony_ci */
27425bb815Sopenharmony_ci
28425bb815Sopenharmony_ci#ifdef __GNUC__
29425bb815Sopenharmony_ci
30425bb815Sopenharmony_ci/*
31425bb815Sopenharmony_ci * Compiler-specific macros relevant for GCC.
32425bb815Sopenharmony_ci */
33425bb815Sopenharmony_ci#define JERRY_ATTR_ALIGNED(ALIGNMENT) __attribute__((aligned(ALIGNMENT)))
34425bb815Sopenharmony_ci#define JERRY_ATTR_ALWAYS_INLINE __attribute__((always_inline))
35425bb815Sopenharmony_ci#define JERRY_ATTR_CONST __attribute__((const))
36425bb815Sopenharmony_ci#define JERRY_ATTR_DEPRECATED __attribute__((deprecated))
37425bb815Sopenharmony_ci#define JERRY_ATTR_FORMAT(...) __attribute__((format(__VA_ARGS__)))
38425bb815Sopenharmony_ci#define JERRY_ATTR_HOT __attribute__((hot))
39425bb815Sopenharmony_ci#define JERRY_ATTR_NOINLINE __attribute__((noinline))
40425bb815Sopenharmony_ci#define JERRY_ATTR_NORETURN __attribute__((noreturn))
41425bb815Sopenharmony_ci#define JERRY_ATTR_PURE __attribute__((pure))
42425bb815Sopenharmony_ci#define JERRY_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
43425bb815Sopenharmony_ci
44425bb815Sopenharmony_ci#define JERRY_LIKELY(x) __builtin_expect(!!(x), 1)
45425bb815Sopenharmony_ci#define JERRY_UNLIKELY(x) __builtin_expect(!!(x), 0)
46425bb815Sopenharmony_ci
47425bb815Sopenharmony_ci#endif /* __GNUC__ */
48425bb815Sopenharmony_ci
49425bb815Sopenharmony_ci#ifdef _MSC_VER
50425bb815Sopenharmony_ci
51425bb815Sopenharmony_ci/*
52425bb815Sopenharmony_ci * Compiler-specific macros relevant for Microsoft Visual C/C++ Compiler.
53425bb815Sopenharmony_ci */
54425bb815Sopenharmony_ci#define JERRY_ATTR_DEPRECATED __declspec(deprecated)
55425bb815Sopenharmony_ci#define JERRY_ATTR_NOINLINE __declspec(noinline)
56425bb815Sopenharmony_ci#define JERRY_ATTR_NORETURN __declspec(noreturn)
57425bb815Sopenharmony_ci
58425bb815Sopenharmony_ci/*
59425bb815Sopenharmony_ci * Microsoft Visual C/C++ Compiler doesn't support for VLA, using _alloca
60425bb815Sopenharmony_ci * instead.
61425bb815Sopenharmony_ci */
62425bb815Sopenharmony_civoid * __cdecl _alloca (size_t _Size);
63425bb815Sopenharmony_ci#define JERRY_VLA(type, name, size) type *name = (type *) (_alloca (sizeof (type) * size))
64425bb815Sopenharmony_ci
65425bb815Sopenharmony_ci#endif /* _MSC_VER */
66425bb815Sopenharmony_ci
67425bb815Sopenharmony_ci/*
68425bb815Sopenharmony_ci * Default empty definitions for all compiler-specific macros. Define any of
69425bb815Sopenharmony_ci * these in a guarded block above (e.g., as for GCC) to fine tune compilation
70425bb815Sopenharmony_ci * for your own compiler. */
71425bb815Sopenharmony_ci
72425bb815Sopenharmony_ci/**
73425bb815Sopenharmony_ci * Function attribute to align function to given number of bytes.
74425bb815Sopenharmony_ci */
75425bb815Sopenharmony_ci#ifndef JERRY_ATTR_ALIGNED
76425bb815Sopenharmony_ci#define JERRY_ATTR_ALIGNED(ALIGNMENT)
77425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_ALIGNED */
78425bb815Sopenharmony_ci
79425bb815Sopenharmony_ci/**
80425bb815Sopenharmony_ci * Function attribute to inline function to all call sites.
81425bb815Sopenharmony_ci */
82425bb815Sopenharmony_ci#ifndef JERRY_ATTR_ALWAYS_INLINE
83425bb815Sopenharmony_ci#define JERRY_ATTR_ALWAYS_INLINE
84425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_ALWAYS_INLINE */
85425bb815Sopenharmony_ci
86425bb815Sopenharmony_ci/**
87425bb815Sopenharmony_ci * Function attribute to declare that function has no effect except the return
88425bb815Sopenharmony_ci * value and it only depends on parameters.
89425bb815Sopenharmony_ci */
90425bb815Sopenharmony_ci#ifndef JERRY_ATTR_CONST
91425bb815Sopenharmony_ci#define JERRY_ATTR_CONST
92425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_CONST */
93425bb815Sopenharmony_ci
94425bb815Sopenharmony_ci/**
95425bb815Sopenharmony_ci * Function attribute to trigger warning if deprecated function is called.
96425bb815Sopenharmony_ci */
97425bb815Sopenharmony_ci#ifndef JERRY_ATTR_DEPRECATED
98425bb815Sopenharmony_ci#define JERRY_ATTR_DEPRECATED
99425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_DEPRECATED */
100425bb815Sopenharmony_ci
101425bb815Sopenharmony_ci/**
102425bb815Sopenharmony_ci * Function attribute to declare that function is variadic and takes a format
103425bb815Sopenharmony_ci * string and some arguments as parameters.
104425bb815Sopenharmony_ci */
105425bb815Sopenharmony_ci#ifndef JERRY_ATTR_FORMAT
106425bb815Sopenharmony_ci#define JERRY_ATTR_FORMAT(...)
107425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_FORMAT */
108425bb815Sopenharmony_ci
109425bb815Sopenharmony_ci/**
110425bb815Sopenharmony_ci * Function attribute to predict that function is a hot spot, and therefore
111425bb815Sopenharmony_ci * should be optimized aggressively.
112425bb815Sopenharmony_ci */
113425bb815Sopenharmony_ci#ifndef JERRY_ATTR_HOT
114425bb815Sopenharmony_ci#define JERRY_ATTR_HOT
115425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_HOT */
116425bb815Sopenharmony_ci
117425bb815Sopenharmony_ci/**
118425bb815Sopenharmony_ci * Function attribute not to inline function ever.
119425bb815Sopenharmony_ci */
120425bb815Sopenharmony_ci#ifndef JERRY_ATTR_NOINLINE
121425bb815Sopenharmony_ci#define JERRY_ATTR_NOINLINE
122425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_NOINLINE */
123425bb815Sopenharmony_ci
124425bb815Sopenharmony_ci/**
125425bb815Sopenharmony_ci * Function attribute to declare that function never returns.
126425bb815Sopenharmony_ci */
127425bb815Sopenharmony_ci#ifndef JERRY_ATTR_NORETURN
128425bb815Sopenharmony_ci#define JERRY_ATTR_NORETURN
129425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_NORETURN */
130425bb815Sopenharmony_ci
131425bb815Sopenharmony_ci/**
132425bb815Sopenharmony_ci * Function attribute to declare that function has no effect except the return
133425bb815Sopenharmony_ci * value and it only depends on parameters and global variables.
134425bb815Sopenharmony_ci */
135425bb815Sopenharmony_ci#ifndef JERRY_ATTR_PURE
136425bb815Sopenharmony_ci#define JERRY_ATTR_PURE
137425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_PURE */
138425bb815Sopenharmony_ci
139425bb815Sopenharmony_ci/**
140425bb815Sopenharmony_ci * Function attribute to place function in given section.
141425bb815Sopenharmony_ci */
142425bb815Sopenharmony_ci#ifndef JERRY_ATTR_SECTION
143425bb815Sopenharmony_ci#define JERRY_ATTR_SECTION(SECTION)
144425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_SECTION */
145425bb815Sopenharmony_ci
146425bb815Sopenharmony_ci/**
147425bb815Sopenharmony_ci * Function attribute to trigger warning if function's caller doesn't use (e.g.,
148425bb815Sopenharmony_ci * check) the return value.
149425bb815Sopenharmony_ci */
150425bb815Sopenharmony_ci#ifndef JERRY_ATTR_WARN_UNUSED_RESULT
151425bb815Sopenharmony_ci#define JERRY_ATTR_WARN_UNUSED_RESULT
152425bb815Sopenharmony_ci#endif /* !JERRY_ATTR_WARN_UNUSED_RESULT */
153425bb815Sopenharmony_ci
154425bb815Sopenharmony_ci/**
155425bb815Sopenharmony_ci * Helper to predict that a condition is likely.
156425bb815Sopenharmony_ci */
157425bb815Sopenharmony_ci#ifndef JERRY_LIKELY
158425bb815Sopenharmony_ci#define JERRY_LIKELY(x) (x)
159425bb815Sopenharmony_ci#endif /* !JERRY_LIKELY */
160425bb815Sopenharmony_ci
161425bb815Sopenharmony_ci/**
162425bb815Sopenharmony_ci * Helper to predict that a condition is unlikely.
163425bb815Sopenharmony_ci */
164425bb815Sopenharmony_ci#ifndef JERRY_UNLIKELY
165425bb815Sopenharmony_ci#define JERRY_UNLIKELY(x) (x)
166425bb815Sopenharmony_ci#endif /* !JERRY_UNLIKELY */
167425bb815Sopenharmony_ci
168425bb815Sopenharmony_ci/**
169425bb815Sopenharmony_ci * Helper to declare (or mimic) a C99 variable-length array.
170425bb815Sopenharmony_ci */
171425bb815Sopenharmony_ci#ifndef JERRY_VLA
172425bb815Sopenharmony_ci#define JERRY_VLA(type, name, size) type name[size]
173425bb815Sopenharmony_ci#endif /* !JERRY_VLA */
174425bb815Sopenharmony_ci
175425bb815Sopenharmony_ci/**
176425bb815Sopenharmony_ci * @}
177425bb815Sopenharmony_ci */
178425bb815Sopenharmony_ci
179425bb815Sopenharmony_ci#ifdef __cplusplus
180425bb815Sopenharmony_ci}
181425bb815Sopenharmony_ci#endif /* __cplusplus */
182425bb815Sopenharmony_ci#endif /* !JERRYSCRIPT_COMPILER_H */
183