4 # Mesa 3-D graphics library
7 # Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 # The above copyright notice and this permission notice shall be included
17 # in all copies or substantial portions of the Software.
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.
27 # Generate the src/X86/glapi_x86.S file.
30 # gloffsets.py >glapi_x86.S
33 # The apispec file must be in the current directory.
40 print '/* DO NOT EDIT - This file generated automatically with glx86asm.py script */'
41 print '#include "assyntax.h"'
42 print '#include "glapioffsets.h"'
44 print '#ifndef __WIN32__'
46 print '#if defined(STDCALL_API)'
47 print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
48 print '#elif defined(USE_MGL_NAMESPACE)'
49 print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
51 print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
54 print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
56 print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)'
57 print '#define GLOBL_FN(x) GLOBL x ; .type x,@function'
59 print '#define GLOBL_FN(x) GLOBL x'
64 print 'EXTERN GLNAME(_glapi_Dispatch)'
72 print '#endif /* __WIN32__ */'
79 def FindOffset(funcName
):
80 for (name
, alias
, offset
) in records
:
88 # Find the size of the arguments on the stack for _stdcall name mangling
89 def FindStackSize(typeList
):
92 if typ
== 'GLdouble' or typ
== 'GLclampd':
101 def EmitFunction(name
, returnType
, argTypeList
, argNameList
, alias
, offset
):
102 argList
= apiparser
.MakeArgList(argTypeList
, argNameList
)
110 # try to find offset from alias name
111 assert dispatchName
!= ''
112 offset
= FindOffset(dispatchName
)
114 #print 'Cannot dispatch %s' % name
119 # save this info in case we need to look up an alias later
120 records
.append((name
, dispatchName
, offset
))
122 # Find the argument stack size for _stdcall name mangling
123 stackSize
= FindStackSize(argTypeList
)
125 # print the assembly code
127 print "GLOBL_FN(GL_PREFIX(%s,%s@%s))" % (name
, name
, stackSize
)
128 print "GL_PREFIX(%s,%s@%s):" % (name
, name
, stackSize
)
129 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX)'
130 print "\tJMP(GL_OFFSET(_gloffset_%s))" % (dispatchName
)
135 apiparser
.ProcessSpecFile("APIspec", EmitFunction
)