some more builtins
[cparser] / builtins.h
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2010 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #ifndef BUILTINS_H
21 #define BUILTINS_H
22
23 #include <stdbool.h>
24
25 /**
26  * GNU builtin or MS intrinsic functions.
27  */
28 typedef enum builtin_kind_t {
29         bk_none = 0,
30         bk_gnu_builtin_alloca,
31         bk_gnu_builtin_huge_val,
32         bk_gnu_builtin_huge_valf,
33         bk_gnu_builtin_huge_vall,
34         bk_gnu_builtin_inf,
35         bk_gnu_builtin_inff,
36         bk_gnu_builtin_infl,
37         bk_gnu_builtin_nan,
38         bk_gnu_builtin_nanf,
39         bk_gnu_builtin_nanl,
40         bk_gnu_builtin_va_end,
41         bk_gnu_builtin_expect,
42         bk_gnu_builtin_return_address,
43         bk_gnu_builtin_frame_address,
44         bk_gnu_builtin_ffs,
45         bk_gnu_builtin_clz,
46         bk_gnu_builtin_ctz,
47         bk_gnu_builtin_popcount,
48         bk_gnu_builtin_parity,
49         bk_gnu_builtin_prefetch,
50         bk_gnu_builtin_trap,
51         bk_gnu_builtin_object_size,
52         bk_gnu_builtin_abort,
53         bk_gnu_builtin_abs,
54         bk_gnu_builtin_labs,
55         bk_gnu_builtin_llabs,
56         bk_gnu_builtin_exit,
57         bk_gnu_builtin_malloc,
58         bk_gnu_builtin_memcmp,
59         bk_gnu_builtin_memcpy,
60         bk_gnu_builtin___memcpy_chk,
61         bk_gnu_builtin_memmove,
62         bk_gnu_builtin_memset,
63         bk_gnu_builtin_strlen,
64         bk_gnu_builtin_strcmp,
65         bk_gnu_builtin_strcpy,
66         bk_gnu_builtin_strncpy,
67         bk_gnu_builtin_strcat,
68         bk_gnu_builtin_strncat,
69
70         bk_ms_rotl,
71         bk_ms_rotr,
72         bk_ms_rotl64,
73         bk_ms_rotr64,
74         bk_ms_byteswap_ushort,
75         bk_ms_byteswap_ulong,
76         bk_ms_byteswap_uint64,
77
78         bk_ms__debugbreak,
79         bk_ms_ReturnAddress,
80         bk_ms_AddressOfReturnAddress,
81         bk_ms__popcount,
82         bk_ms_enable,
83         bk_ms_disable,
84         bk_ms__inbyte,
85         bk_ms__inword,
86         bk_ms__indword,
87         bk_ms__outbyte,
88         bk_ms__outword,
89         bk_ms__outdword,
90         bk_ms__ud2,
91         bk_ms_BitScanForward,
92         bk_ms_BitScanReverse,
93         bk_ms_InterlockedExchange,
94         bk_ms_InterlockedExchange64,
95         bk_ms__readeflags,
96         bk_ms__writeeflags,
97 } builtin_kind_t;
98
99 /**
100  * Create predefined gnu builtins.
101  */
102 void create_gnu_builtins(void);
103
104 /**
105  * Create predefined MS intrinsics.
106  */
107 void create_microsoft_intrinsics(void);
108
109 /**
110  * Some of the gnu builtins are simply more elaborate declarations of
111  * library functions. Return the library function name so we can simply
112  * replace the builtins with these during code generation
113  */
114 entity_t *get_builtin_replacement(const entity_t *builtin_entity);
115
116 int get_builtin_chk_arg_pos(builtin_kind_t kind);
117
118 #endif