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