Make generation of matypes.h more transparent.
[mesa.git] / src / mesa / x86 / gen_matypes.c
1 /* $Id: gen_matypes.c,v 1.2 2001/03/29 03:41:40 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
28 */
29
30 /*
31 * This generates an asm version of mtypes.h (called matypes.h), so that
32 * Mesa's x86 assembly code can access the internal structures easily.
33 * This will be particularly useful when developing new x86 asm code for
34 * Mesa, including lighting, clipping, texture image conversion etc.
35 */
36
37 #ifdef PC_HEADER
38 #include "all.h"
39 #else
40 #include "glheader.h"
41 #include "mtypes.h"
42 #include "tnl/t_context.h"
43 #endif
44
45 #undef offsetof
46 #define offsetof( type, member ) ((size_t) &((type *)0)->member)
47
48
49 #define OFFSET_HEADER( x ) \
50 do { \
51 printf( "\n" ); \
52 printf( "\n" ); \
53 printf( "/* =====================================================" \
54 "========\n" ); \
55 printf( " * Offsets for %s\n", x ); \
56 printf( " */\n" ); \
57 printf( "\n" ); \
58 } while (0)
59
60 #define DEFINE_HEADER( x ) \
61 do { \
62 printf( "\n" ); \
63 printf( "/*\n" ); \
64 printf( " * Flags for %s\n", x ); \
65 printf( " */\n" ); \
66 printf( "\n" ); \
67 } while (0)
68
69 #define OFFSET( s, t, m ) \
70 printf( "#define %s\t%d\n", s, offsetof( t, m ) );
71
72 #define SIZEOF( s, t ) \
73 printf( "#define %s\t%d\n", s, sizeof(t) );
74
75 #define DEFINE( s, d ) \
76 printf( "#define %s\t0x%x\n", s, d );
77
78
79
80 int main( int argc, char **argv )
81 {
82 printf( "/*\n" );
83 printf( " * This file is automatically generated from the Mesa internal type\n" );
84 printf( " * definitions. Do not edit directly.\n" );
85 printf( " */\n" );
86 printf( "\n" );
87 printf( "#ifndef __ASM_TYPES_H__\n" );
88 printf( "#define __ASM_TYPES_H__\n" );
89 printf( "\n" );
90 printf( "#include \"assyntax.h\"\n" );
91
92
93 /* GLcontext offsets:
94 */
95 OFFSET_HEADER( "GLcontext" );
96
97 OFFSET( "CTX_DRIVER_CTX ", GLcontext, DriverCtx );
98 printf( "\n" );
99 OFFSET( "CTX_LIGHT_ENABLED ", GLcontext, Light.Enabled );
100 OFFSET( "CTX_LIGHT_SHADE_MODEL ", GLcontext, Light.ShadeModel );
101 OFFSET( "CTX_LIGHT_COLOR_MAT_FACE ", GLcontext, Light.ColorMaterialFace );
102 OFFSET( "CTX_LIGHT_COLOR_MAT_MODE ", GLcontext, Light.ColorMaterialMode );
103 OFFSET( "CTX_LIGHT_COLOR_MAT_MASK ", GLcontext, Light.ColorMaterialBitmask );
104 OFFSET( "CTX_LIGHT_COLOR_MAT_ENABLED ", GLcontext, Light.ColorMaterialEnabled );
105 OFFSET( "CTX_LIGHT_ENABLED_LIST ", GLcontext, Light.EnabledList );
106 OFFSET( "CTX_LIGHT_NEED_VERTS ", GLcontext, Light._NeedVertices );
107 OFFSET( "CTX_LIGHT_FLAGS ", GLcontext, Light._Flags );
108 OFFSET( "CTX_LIGHT_BASE_COLOR ", GLcontext, Light._BaseColor );
109 OFFSET( "CTX_LIGHT_BASE_ALPHA ", GLcontext, Light._BaseAlpha );
110
111
112 /* struct vertex_buffer offsets:
113 */
114 OFFSET_HEADER( "struct vertex_buffer" );
115
116 OFFSET( "VB_SIZE ", struct vertex_buffer, Size );
117 OFFSET( "VB_COUNT ", struct vertex_buffer, Count );
118 printf( "\n" );
119 OFFSET( "VB_FIRST_CLIPPED ", struct vertex_buffer, FirstClipped );
120 OFFSET( "VB_FIRST_PRIMITIVE ", struct vertex_buffer, FirstPrimitive );
121 printf( "\n" );
122 OFFSET( "VB_ELTS ", struct vertex_buffer, Elts );
123 OFFSET( "VB_OBJ_PTR ", struct vertex_buffer, ObjPtr );
124 OFFSET( "VB_EYE_PTR ", struct vertex_buffer, EyePtr );
125 OFFSET( "VB_CLIP_PTR ", struct vertex_buffer, ClipPtr );
126 OFFSET( "VB_PROJ_CLIP_PTR ", struct vertex_buffer, ProjectedClipPtr );
127 OFFSET( "VB_CLIP_OR_MASK ", struct vertex_buffer, ClipOrMask );
128 OFFSET( "VB_CLIP_MASK ", struct vertex_buffer, ClipMask );
129 OFFSET( "VB_NORMAL_PTR ", struct vertex_buffer, NormalPtr );
130 OFFSET( "VB_EDGE_FLAG ", struct vertex_buffer, EdgeFlag );
131 OFFSET( "VB_TEX0_COORD_PTR ", struct vertex_buffer, TexCoordPtr[0] );
132 OFFSET( "VB_TEX1_COORD_PTR ", struct vertex_buffer, TexCoordPtr[1] );
133 OFFSET( "VB_TEX2_COORD_PTR ", struct vertex_buffer, TexCoordPtr[2] );
134 OFFSET( "VB_TEX3_COORD_PTR ", struct vertex_buffer, TexCoordPtr[3] );
135 OFFSET( "VB_INDEX_PTR ", struct vertex_buffer, IndexPtr );
136 OFFSET( "VB_COLOR_PTR ", struct vertex_buffer, ColorPtr );
137 OFFSET( "VB_SECONDARY_COLOR_PTR ", struct vertex_buffer, SecondaryColorPtr );
138 OFFSET( "VB_FOG_COORD_PTR ", struct vertex_buffer, FogCoordPtr );
139 OFFSET( "VB_POINT_SIZE_PTR ", struct vertex_buffer, PointSizePtr );
140 OFFSET( "VB_MATERIAL ", struct vertex_buffer, Material );
141 OFFSET( "VB_MATERIAL_MASK ", struct vertex_buffer, MaterialMask );
142 OFFSET( "VB_FLAG ", struct vertex_buffer, Flag );
143 OFFSET( "VB_PRIMITIVE ", struct vertex_buffer, Primitive );
144 OFFSET( "VB_PRIMITIVE_LENGTH ", struct vertex_buffer, PrimitiveLength );
145 printf( "\n" );
146 OFFSET( "VB_IMPORTABLE_DATA ", struct vertex_buffer, importable_data );
147 printf( "\n" );
148 OFFSET( "VB_LAST_CLIPPED ", struct vertex_buffer, LastClipped );
149
150 DEFINE_HEADER( "struct vertex_buffer" );
151
152 DEFINE( "VERT_OBJ ", VERT_OBJ );
153 DEFINE( "VERT_RGBA ", VERT_RGBA );
154 DEFINE( "VERT_NORM ", VERT_NORM );
155 DEFINE( "VERT_INDEX ", VERT_INDEX );
156 DEFINE( "VERT_EDGE ", VERT_EDGE );
157 DEFINE( "VERT_SPEC_RGB ", VERT_SPEC_RGB );
158 DEFINE( "VERT_FOG_COORD ", VERT_FOG_COORD );
159 DEFINE( "VERT_TEX0 ", VERT_TEX0 );
160 DEFINE( "VERT_TEX1 ", VERT_TEX1 );
161 DEFINE( "VERT_TEX2 ", VERT_TEX2 );
162 DEFINE( "VERT_TEX3 ", VERT_TEX3 );
163 DEFINE( "VERT_EVAL_C1 ", VERT_EVAL_C1 );
164 DEFINE( "VERT_EVAL_C2 ", VERT_EVAL_C2 );
165 DEFINE( "VERT_EVAL_P1 ", VERT_EVAL_P1 );
166 DEFINE( "VERT_EVAL_P2 ", VERT_EVAL_P2 );
167 DEFINE( "VERT_OBJ_3 ", VERT_OBJ_3 );
168 DEFINE( "VERT_OBJ_4 ", VERT_OBJ_4 );
169 DEFINE( "VERT_MATERIAL ", VERT_MATERIAL );
170 DEFINE( "VERT_ELT ", VERT_ELT );
171 DEFINE( "VERT_BEGIN ", VERT_BEGIN );
172 DEFINE( "VERT_END ", VERT_END );
173 DEFINE( "VERT_END_VB ", VERT_END_VB );
174 DEFINE( "VERT_POINT_SIZE ", VERT_POINT_SIZE );
175 DEFINE( "VERT_EYE ", VERT_EYE );
176 DEFINE( "VERT_CLIP ", VERT_CLIP );
177 printf( "\n" );
178 DEFINE( "VERT_OBJ_23 ", VERT_OBJ_3 );
179 DEFINE( "VERT_OBJ_234 ", VERT_OBJ_4 );
180
181
182 /* GLvector3f offsets:
183 */
184 OFFSET_HEADER( "GLvector3f" );
185
186 OFFSET( "V3F_DATA ", GLvector3f, data );
187 OFFSET( "V3F_START ", GLvector3f, start );
188 OFFSET( "V3F_COUNT ", GLvector3f, count );
189 OFFSET( "V3F_STRIDE ", GLvector3f, stride );
190 OFFSET( "V3F_FLAGS ", GLvector3f, flags );
191
192
193 /* GLvector4f offsets:
194 */
195 OFFSET_HEADER( "GLvector4f" );
196
197 OFFSET( "V4F_DATA ", GLvector4f, data );
198 OFFSET( "V4F_START ", GLvector4f, start );
199 OFFSET( "V4F_COUNT ", GLvector4f, count );
200 OFFSET( "V4F_STRIDE ", GLvector4f, stride );
201 OFFSET( "V4F_SIZE ", GLvector4f, size );
202 OFFSET( "V4F_FLAGS ", GLvector4f, flags );
203
204 DEFINE_HEADER( "GLvector4f" );
205
206 DEFINE( "VEC_MALLOC ", VEC_MALLOC );
207 DEFINE( "VEC_NOT_WRITEABLE ", VEC_NOT_WRITEABLE );
208 DEFINE( "VEC_BAD_STRIDE ", VEC_BAD_STRIDE );
209 printf( "\n" );
210 DEFINE( "VEC_SIZE_1 ", VEC_SIZE_1 );
211 DEFINE( "VEC_SIZE_2 ", VEC_SIZE_2 );
212 DEFINE( "VEC_SIZE_3 ", VEC_SIZE_3 );
213 DEFINE( "VEC_SIZE_4 ", VEC_SIZE_4 );
214
215
216 /* GLmatrix offsets:
217 */
218 OFFSET_HEADER( "GLmatrix" );
219
220 OFFSET( "MATRIX_DATA ", GLmatrix, m );
221 OFFSET( "MATRIX_INV ", GLmatrix, inv );
222 OFFSET( "MATRIX_FLAGS ", GLmatrix, flags );
223 OFFSET( "MATRIX_TYPE ", GLmatrix, type );
224
225
226 /* struct gl_light offsets:
227 */
228 OFFSET_HEADER( "struct gl_light" );
229
230 OFFSET( "LIGHT_NEXT ", struct gl_light, next );
231 OFFSET( "LIGHT_PREV ", struct gl_light, prev );
232 printf( "\n" );
233 OFFSET( "LIGHT_AMBIENT ", struct gl_light, Ambient );
234 OFFSET( "LIGHT_DIFFUSE ", struct gl_light, Diffuse );
235 OFFSET( "LIGHT_SPECULAR ", struct gl_light, Specular );
236 OFFSET( "LIGHT_EYE_POSITION ", struct gl_light, EyePosition );
237 OFFSET( "LIGHT_EYE_DIRECTION ", struct gl_light, EyeDirection );
238 OFFSET( "LIGHT_SPOT_EXPONENT ", struct gl_light, SpotExponent );
239 OFFSET( "LIGHT_SPOT_CUTOFF ", struct gl_light, SpotCutoff );
240 OFFSET( "LIGHT_COS_CUTOFF ", struct gl_light, _CosCutoff );
241 OFFSET( "LIGHT_CONST_ATTEN ", struct gl_light, ConstantAttenuation );
242 OFFSET( "LIGHT_LINEAR_ATTEN ", struct gl_light, LinearAttenuation );
243 OFFSET( "LIGHT_QUADRATIC_ATTEN ", struct gl_light, QuadraticAttenuation );
244 OFFSET( "LIGHT_ENABLED ", struct gl_light, Enabled );
245 printf( "\n" );
246 OFFSET( "LIGHT_FLAGS ", struct gl_light, _Flags );
247 printf( "\n" );
248 OFFSET( "LIGHT_POSITION ", struct gl_light, _Position );
249 OFFSET( "LIGHT_VP_INF_NORM ", struct gl_light, _VP_inf_norm );
250 OFFSET( "LIGHT_H_INF_NORM ", struct gl_light, _h_inf_norm );
251 OFFSET( "LIGHT_NORM_DIRECTION ", struct gl_light, _NormDirection );
252 OFFSET( "LIGHT_VP_INF_SPOT_ATTEN ", struct gl_light, _VP_inf_spot_attenuation );
253 printf( "\n" );
254 OFFSET( "LIGHT_SPOT_EXP_TABLE ", struct gl_light, _SpotExpTable );
255 OFFSET( "LIGHT_MAT_AMBIENT ", struct gl_light, _MatAmbient );
256 OFFSET( "LIGHT_MAT_DIFFUSE ", struct gl_light, _MatDiffuse );
257 OFFSET( "LIGHT_MAT_SPECULAR ", struct gl_light, _MatSpecular );
258 printf( "\n" );
259 SIZEOF( "SIZEOF_GL_LIGHT ", struct gl_light );
260
261 DEFINE_HEADER( "struct gl_light" );
262
263 DEFINE( "LIGHT_SPOT ", LIGHT_SPOT );
264 DEFINE( "LIGHT_LOCAL_VIEWER ", LIGHT_LOCAL_VIEWER );
265 DEFINE( "LIGHT_POSITIONAL ", LIGHT_POSITIONAL );
266 printf( "\n" );
267 DEFINE( "LIGHT_NEED_VERTICES ", LIGHT_NEED_VERTICES );
268
269
270 /* struct gl_lightmodel offsets:
271 */
272 OFFSET_HEADER( "struct gl_lightmodel" );
273
274 OFFSET( "LIGHT_MODEL_AMBIENT ", struct gl_lightmodel, Ambient );
275 OFFSET( "LIGHT_MODEL_LOCAL_VIEWER ", struct gl_lightmodel, LocalViewer );
276 OFFSET( "LIGHT_MODEL_TWO_SIDE ", struct gl_lightmodel, TwoSide );
277 OFFSET( "LIGHT_MODEL_COLOR_CONTROL ", struct gl_lightmodel, ColorControl );
278
279
280 printf( "\n" );
281 printf( "\n" );
282 printf( "#endif /* __ASM_TYPES_H__ */\n" );
283
284 return 0;
285 }