blob: f881abeea94c3d4db7bc29afb45ef3fcb75b9c0c [file] [log] [blame]
Brian Paul5a8a6d92000-05-11 23:14:57 +00001#!/usr/bin/env python
2
Brian Paul35883ce2002-06-11 01:26:58 +00003# $Id: glx86asm.py,v 1.6 2002/06/11 01:26:58 brianp Exp $
Brian Paul5a8a6d92000-05-11 23:14:57 +00004
5# Mesa 3-D graphics library
Brian Paul6c0d72f2001-11-18 22:42:57 +00006# Version: 4.1
Brian Paul5a8a6d92000-05-11 23:14:57 +00007#
Brian Paul6c0d72f2001-11-18 22:42:57 +00008# Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
Brian Paul5a8a6d92000-05-11 23:14:57 +00009#
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
Brian Paul6c0d72f2001-11-18 22:42:57 +000028# Generate the src/X86/glapi_x86.S file.
Brian Paul5a8a6d92000-05-11 23:14:57 +000029#
30# Usage:
Brian Paul6c0d72f2001-11-18 22:42:57 +000031# gloffsets.py >glapi_x86.S
Brian Paul5a8a6d92000-05-11 23:14:57 +000032#
33# Dependencies:
Brian Paul6c0d72f2001-11-18 22:42:57 +000034# The apispec file must be in the current directory.
Brian Paul5a8a6d92000-05-11 23:14:57 +000035
36
Brian Paul6c0d72f2001-11-18 22:42:57 +000037import apiparser
Brian Paul5a8a6d92000-05-11 23:14:57 +000038
39
40def 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)'
Brian Paul37cfb3b2000-09-06 17:33:40 +000048 print '#define GL_PREFIX(n) GLNAME(CONCAT(mgl,n))'
Brian Paul5a8a6d92000-05-11 23:14:57 +000049 print '#else'
Brian Paul37cfb3b2000-09-06 17:33:40 +000050 print '#define GL_PREFIX(n) GLNAME(CONCAT(gl,n))'
Brian Paul5a8a6d92000-05-11 23:14:57 +000051 print '#endif'
52 print ''
53 print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))'
54 print ''
Brian Paulf9e75c32002-04-02 16:18:20 +000055 print '#if defined(GNU_ASSEMBLER) && !defined(DJGPP)'
Brian Paul5a8a6d92000-05-11 23:14:57 +000056 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 ''
Brian Paul35883ce2002-06-11 01:26:58 +000062 print 'EXTERN GLNAME(_glapi_Dispatch)'
63 print ''
Brian Paul5a8a6d92000-05-11 23:14:57 +000064 return
Brian Paul6c0d72f2001-11-18 22:42:57 +000065#enddef
Brian Paul5a8a6d92000-05-11 23:14:57 +000066
67
68def PrintTail():
69 print ''
70 print '#endif /* __WIN32__ */'
Brian Paul6c0d72f2001-11-18 22:42:57 +000071#enddef
Brian Paul5a8a6d92000-05-11 23:14:57 +000072
73
Brian Paul6c0d72f2001-11-18 22:42:57 +000074
75records = []
76
77def FindOffset(funcName):
78 for (name, alias, offset) in records:
79 if name == funcName:
80 return offset
81 #endif
82 #endfor
83 return -1
84#enddef
85
86def EmitFunction(name, returnType, argTypeList, argNameList, alias, offset):
87 argList = apiparser.MakeArgList(argTypeList, argNameList)
88 if alias != '':
89 dispatchName = alias
90 else:
91 dispatchName = name
92 #endif
93
94 if offset < 0:
95 # try to find offset from alias name
96 assert dispatchName != ''
97 offset = FindOffset(dispatchName)
98 if offset == -1:
99 #print 'Cannot dispatch %s' % name
100 return
101 #endif
102 #endif
103
104 # save this info in case we need to look up an alias later
105 records.append((name, dispatchName, offset))
106
107 # print the assembly code
Brian Paul5a8a6d92000-05-11 23:14:57 +0000108 print 'ALIGNTEXT16'
109 print "GLOBL_FN(GL_PREFIX(%s))" % (name)
110 print "GL_PREFIX(%s):" % (name)
Brian Paul35883ce2002-06-11 01:26:58 +0000111 print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX)'
Brian Paul6c0d72f2001-11-18 22:42:57 +0000112 print "\tJMP(GL_OFFSET(_gloffset_%s))" % (dispatchName)
Brian Paul5a8a6d92000-05-11 23:14:57 +0000113 print ''
Brian Paul5a8a6d92000-05-11 23:14:57 +0000114
115#enddef
116
117
118
119PrintHead()
Brian Paul6c0d72f2001-11-18 22:42:57 +0000120apiparser.ProcessSpecFile("APIspec", EmitFunction)
Brian Paul5a8a6d92000-05-11 23:14:57 +0000121PrintTail()