Python script for making glapi_sparc.S
[mesa.git] / src / mesa / glapi / glsparcasm.py
1 #!/usr/bin/env python
2
3 # $Id: glsparcasm.py,v 1.1 2001/06/05 04:30:03 davem69 Exp $
4
5 # Mesa 3-D graphics library
6 # Version: 3.5
7 #
8 # Copyright (C) 1999-2000 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 glapi_sparc.S assembly language file.
29 #
30 # Usage:
31 # glsparcasm.py >glapi_sparc.S
32 #
33 # Dependencies:
34 # The gl.spec file from the SI must be in the current directory.
35 #
36 # Brian Paul 11 May 2000
37 # David S. Miller 4 Jun 2001
38
39 import string
40 import re
41
42
43 def PrintHead():
44 print '/* DO NOT EDIT - This file generated automatically with glsparcasm.py script */'
45 print '#include "glapioffsets.h"'
46 print ''
47 print '#define GL_PREFIX(n) gl##n'
48 print '#define GLOBL_FN(x) .globl x ; .type x,@function'
49 print ''
50 print '/* The _glapi_Dispatch symbol addresses get relocated into the'
51 print ' * sethi/or instruction sequences below at library init time.'
52 print ' */'
53 print ''
54 print '.text'
55 print '.align 64'
56 print ''
57 return
58 #endif
59
60 def PrintTail():
61 print '\t nop'
62 print ''
63 #endif
64
65
66 def GenerateDispatchCode(name, offset):
67 print ''
68 print "GLOBL_FN(GL_PREFIX(%s))" % (name)
69 print "GL_PREFIX(%s):" % (name)
70 print '#ifdef __sparc_v9__'
71 print '\tsethi\t%hi(0x00000000), %g2'
72 print '\tsethi\t%hi(0x00000000), %g1'
73 print '\tor\t%g2, %lo(0x00000000), %g2'
74 print '\tor\t%g1, %lo(0x00000000), %g1'
75 print '\tsllx\t%g2, 32, %g2'
76 print '\tor\t%g1, %g2, %g1'
77 print "\tsethi\t%%hi(8 * _gloffset_%s), %%g2" % (offset)
78 print "\tor\t%%g2, %%lo(8 * _gloffset_%s), %%g2" % (offset)
79 print '\tldx\t[%g1 + %g2], %g3'
80 print '#else'
81 print '\tsethi\t%hi(0x00000000), %g1'
82 print '\tor\t%g1, %lo(0x00000000), %g1'
83 print "\tld\t[%%g1 + (4 * _gloffset_%s)], %%g3" % (offset)
84 print '#endif'
85 print '\tjmpl\t%g3, %g0'
86 #enddef
87
88
89 def FindAlias(list, funcName):
90 for i in range(0, len(list)):
91 entry = list[i]
92 if entry[0] == funcName:
93 return entry[1]
94 #endif
95 #endfor
96 return ''
97 #enddef
98
99
100
101 def PrintDefines():
102 functionPattern = re.compile('^[a-zA-Z0-9]+\(')
103 functionNamePattern = re.compile('^[a-zA-Z0-9]+')
104
105 funcName = ''
106 functions = [ ]
107
108 f = open('gl.spec')
109 for line in f.readlines():
110
111 m = functionPattern.match(line)
112 if m:
113 # extract funcName
114 n = functionNamePattern.findall(line)
115 funcName = n[0]
116
117 m = string.split(line)
118 if len(m) > 1:
119 if m[0] == 'param':
120 paramName = m[1]
121 if m[0] == 'offset':
122 if m[1] == '?':
123 #print 'WARNING skipping', funcName
124 noop = 0
125 else:
126 entry = [ funcName, funcName ]
127 functions.append(entry)
128 #endif
129 elif m[0] == 'alias':
130 aliasedName = FindAlias(functions, m[1])
131 if aliasedName:
132 entry = [ funcName, aliasedName ]
133 functions.append(entry)
134 else:
135 print 'WARNING: alias to unknown function:', aliasedName
136 #endif
137 #endif
138 #endif
139 #endfor
140
141 # Now generate the assembly dispatch code
142 for i in range(0, len(functions)):
143 entry = functions[i]
144 GenerateDispatchCode( entry[0], entry[1] )
145
146 #enddef
147
148
149
150 PrintHead()
151 PrintDefines()
152 PrintTail()