mapi: Add a generic C dispatcher.
[mesa.git] / src / mapi / mapi / mapi_tmp.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.9
4 *
5 * Copyright (C) 2010 LunarG Inc.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Chia-I Wu <olv@lunarg.com>
27 */
28
29 #include "u_macros.h"
30
31 #ifndef MAPI_ABI_HEADER
32 #error "MAPI_ABI_HEADER must be defined"
33 #endif
34
35
36 /**
37 * Get API defines.
38 */
39 #ifdef MAPI_TMP_DEFINES
40 # define MAPI_ABI_DEFINES
41 # include MAPI_ABI_HEADER
42
43 #ifndef MAPI_ABI_PREFIX
44 #error "MAPI_ABI_PREFIX must be defined"
45 #endif
46 #ifndef MAPI_ABI_PUBLIC
47 #error "MAPI_ABI_PUBLIC must be defined"
48 #endif
49 #ifndef MAPI_ABI_ATTR
50 #error "MAPI_ABI_ATTR must be defined"
51 #endif
52
53 #undef MAPI_TMP_DEFINES
54 #endif /* MAPI_TMP_DEFINES */
55
56
57 /**
58 * Generate fields of struct mapi_table.
59 */
60 #ifdef MAPI_TMP_TABLE
61 # define MAPI_ABI_ENTRY(ret, name, params) \
62 ret (MAPI_ABI_ATTR *name) params;
63 # define MAPI_DYNAMIC_ENTRY(ret, name, params) \
64 ret (MAPI_ABI_ATTR *name) params;
65 # include MAPI_ABI_HEADER
66 #undef MAPI_TMP_TABLE
67 #endif /* MAPI_TMP_TABLE */
68
69
70 /**
71 * Declare public entries.
72 */
73 #ifdef MAPI_TMP_PUBLIC_DECLARES
74 # define MAPI_ABI_ENTRY(ret, name, params) \
75 MAPI_ABI_PUBLIC ret MAPI_ABI_ATTR U_CONCAT(MAPI_ABI_PREFIX, name) params;
76 # define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
77 MAPI_ABI_ENTRY(ret, name, params);
78 # define MAPI_ABI_ENTRY_HIDDEN(ret, name, params) \
79 HIDDEN ret MAPI_ABI_ATTR U_CONCAT(MAPI_ABI_PREFIX, name) params;
80 # define MAPI_ALIAS_ENTRY_HIDDEN(alias, ret, name, params) \
81 MAPI_ABI_ENTRY_HIDDEN(ret, name, params)
82 # include MAPI_ABI_HEADER
83 #undef MAPI_TMP_PUBLIC_DECLARES
84 #endif /* MAPI_TMP_PUBLIC_DECLARES */
85
86
87 /**
88 * Generate string pool and public stubs.
89 */
90 #ifdef MAPI_TMP_PUBLIC_STUBS
91 /* define the string pool */
92 static const char public_string_pool[] =
93 # define MAPI_ABI_ENTRY(ret, name, params) \
94 U_STRINGIFY(name) "\0"
95 # define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
96 MAPI_ABI_ENTRY(ret, name, params)
97 # include MAPI_ABI_HEADER
98 ;
99 /* define public_sorted_indices */
100 # define MAPI_ABI_SORTED_INDICES public_sorted_indices
101 # include MAPI_ABI_HEADER
102
103 /* define public_stubs */
104 static const struct mapi_stub public_stubs[] = {
105 # define MAPI_ABI_ENTRY(ret, name, params) \
106 { (mapi_func) U_CONCAT(MAPI_ABI_PREFIX, name), \
107 MAPI_SLOT_ ## name, (void *) MAPI_POOL_ ## name },
108 # define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
109 MAPI_ABI_ENTRY(ret, name, params)
110 # include MAPI_ABI_HEADER
111 { NULL, -1, (void *) -1 }
112 };
113
114 #undef MAPI_TMP_PUBLIC_STUBS
115 #endif /* MAPI_TMP_PUBLIC_STUBS */
116
117
118 /**
119 * Generate public entries.
120 */
121 #ifdef MAPI_TMP_PUBLIC_ENTRIES
122 # define MAPI_ABI_ENTRY(ret, name, params) \
123 ret MAPI_ABI_ATTR U_CONCAT(MAPI_ABI_PREFIX, name) params
124 # define MAPI_ABI_CODE(ret, name, args) \
125 { \
126 const struct mapi_table *tbl = u_current_get(); \
127 tbl->name args; \
128 }
129 # define MAPI_ABI_CODE_RETURN(ret, name, args) \
130 { \
131 const struct mapi_table *tbl = u_current_get(); \
132 return tbl->name args; \
133 }
134 # define MAPI_ALIAS_ENTRY(alias, ret, name, params) \
135 MAPI_ABI_ENTRY(ret, name, params)
136 # define MAPI_ALIAS_CODE(alias, ret, name, args) \
137 MAPI_ABI_CODE(ret, alias, args)
138 # define MAPI_ALIAS_CODE_RETURN(alias, ret, name, args) \
139 MAPI_ABI_CODE_RETURN(ret, alias, args)
140 # include MAPI_ABI_HEADER
141 #undef MAPI_TMP_PUBLIC_ENTRIES
142 #endif /* MAPI_TMP_PUBLIC_ENTRIES */
143
144
145 /**
146 * Generate noop entries.
147 */
148 #ifdef MAPI_TMP_NOOP_ARRAY
149 #ifdef DEBUG
150 # define MAPI_ABI_ENTRY(ret, name, params) \
151 static ret MAPI_ABI_ATTR U_CONCAT(noop_, name) params
152 # define MAPI_ABI_CODE(ret, name, args) \
153 { \
154 noop_warn(U_CONCAT_STR(MAPI_ABI_PREFIX, name)); \
155 }
156 # define MAPI_ABI_CODE_RETURN(ret, name, args) \
157 { \
158 noop_warn(U_CONCAT_STR(MAPI_ABI_PREFIX, name)); \
159 return (ret) 0; \
160 }
161 # include MAPI_ABI_HEADER
162
163 /* define the noop function array that may be casted to mapi_table */
164 const mapi_func table_noop_array[] = {
165 # define MAPI_ABI_ENTRY(ret, name, params) \
166 (mapi_func) U_CONCAT(noop_, name),
167 # define MAPI_DYNAMIC_ENTRY(ret, name, params) \
168 (mapi_func) noop_generic,
169 # include MAPI_ABI_HEADER
170 (mapi_func) noop_generic
171 };
172
173 #else /* DEBUG */
174
175 const mapi_func table_noop_array[] = {
176 # define MAPI_ABI_ENTRY(ret, name, params) \
177 (mapi_func) noop_generic,
178 # define MAPI_DYNAMIC_ENTRY(ret, name, params) \
179 (mapi_func) noop_generic,
180 # include MAPI_ABI_HEADER
181 (mapi_func) noop_generic
182 };
183
184 #endif /* DEBUG */
185 #undef MAPI_TMP_NOOP_ARRAY
186 #endif /* MAPI_TMP_NOOP_ARRAY */