1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#!/usr/bin/env python
# $Id: glx86asm.py,v 1.6.14.1 2003/11/21 15:49:38 keithw Exp $
# Mesa 3-D graphics library
# Version: 4.1
#
# Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Generate the src/X86/glapi_x86.S file.
#
# Usage:
# gloffsets.py >glapi_x86.S
#
# Dependencies:
# The apispec file must be in the current directory.
import apiparser
def PrintHead():
print '/* DO NOT EDIT - This file generated automatically with glx86asm.py script */'
print '#include "assyntax.h"'
print '#include "glapioffsets.h"'
print ''
print '#ifndef __WIN32__'
print ''
print '#if defined(STDCALL_API)'
print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n2))'
print '#elif defined(USE_MGL_NAMESPACE)'
print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(mgl,n))'
print '#else'
print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))'
print '#endif'
print ''
print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
print ''
print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)'
print '#define GLOBL_FN(x) GLOBL x ; .type x,@function'
print '#else'
print '#define GLOBL_FN(x) GLOBL x'
print '#endif'
print ''
print 'SEG_TEXT'
print ''
print 'EXTERN GLNAME(_glapi_Dispatch)'
print ''
return
#enddef
def PrintTail():
print ''
print '#endif /* __WIN32__ */'
#enddef
records = []
def FindOffset(funcName):
for (name, alias, offset) in records:
if name == funcName:
return offset
#endif
#endfor
return -1
#enddef
# Find the size of the arguments on the stack for _stdcall name mangling
def FindStackSize(typeList):
result = 0
for typ in typeList:
if typ == 'GLdouble' or typ == 'GLclampd':
result += 8;
else:
result += 4;
#endif
#endfor
return result
#enddef
def EmitFunction(name, returnType, argTypeList, argNameList, alias, offset):
argList = apiparser.MakeArgList(argTypeList, argNameList)
if alias != '':
dispatchName = alias
else:
dispatchName = name
#endif
if offset < 0:
# try to find offset from alias name
assert dispatchName != ''
offset = FindOffset(dispatchName)
if offset == -1:
#print 'Cannot dispatch %s' % name
return
#endif
#endif
# save this info in case we need to look up an alias later
records.append((name, dispatchName, offset))
# Find the argument stack size for _stdcall name mangling
stackSize = FindStackSize(argTypeList)
# print the assembly code
print 'ALIGNTEXT16'
print "GLOBL_FN(GL_PREFIX(%s,%s@%s))" % (name, name, stackSize)
print "GL_PREFIX(%s,%s@%s):" % (name, name, stackSize)
print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX)'
print "\tJMP(GL_OFFSET(_gloffset_%s))" % (dispatchName)
print ''
#enddef
PrintHead()
apiparser.ProcessSpecFile("APIspec", EmitFunction)
PrintTail()
|