Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 3 | |
| 4 | # Mesa 3-D graphics library |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 5 | # Version: 4.1 |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 6 | # |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 7 | # Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 8 | # |
| 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: |
| 15 | # |
| 16 | # The above copyright notice and this permission notice shall be included |
| 17 | # in all copies or substantial portions of the Software. |
| 18 | # |
| 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. |
| 25 | |
| 26 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 27 | # Generate the src/X86/glapi_x86.S file. |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 28 | # |
| 29 | # Usage: |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 30 | # gloffsets.py >glapi_x86.S |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 31 | # |
| 32 | # Dependencies: |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 33 | # The apispec file must be in the current directory. |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 34 | |
| 35 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 36 | import apiparser |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 37 | |
| 38 | |
| 39 | def PrintHead(): |
| 40 | print '/* DO NOT EDIT - This file generated automatically with glx86asm.py script */' |
| 41 | print '#include "assyntax.h"' |
| 42 | print '#include "glapioffsets.h"' |
| 43 | print '' |
| 44 | print '#ifndef __WIN32__' |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 45 | print '' |
| 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))' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 50 | print '#else' |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 51 | print '#define GL_PREFIX(n,n2) GLNAME(CONCAT(gl,n))' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 52 | print '#endif' |
| 53 | print '' |
| 54 | print '#define GL_OFFSET(x) CODEPTR(REGOFF(4 * x, EAX))' |
| 55 | print '' |
Daniel Borca | 79fa6b9 | 2003-10-23 13:28:05 +0000 | [diff] [blame] | 56 | print '#if defined(GNU_ASSEMBLER) && !defined(__DJGPP__) && !defined(__MINGW32__)' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 57 | print '#define GLOBL_FN(x) GLOBL x ; .type x,@function' |
| 58 | print '#else' |
| 59 | print '#define GLOBL_FN(x) GLOBL x' |
| 60 | print '#endif' |
| 61 | print '' |
Kendall Bennett | 9b77fb7 | 2003-10-14 23:47:21 +0000 | [diff] [blame] | 62 | print 'SEG_TEXT' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 63 | print '' |
Brian Paul | 35883ce | 2002-06-11 01:26:58 +0000 | [diff] [blame] | 64 | print 'EXTERN GLNAME(_glapi_Dispatch)' |
| 65 | print '' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 66 | return |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 67 | #enddef |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 68 | |
| 69 | |
| 70 | def PrintTail(): |
| 71 | print '' |
| 72 | print '#endif /* __WIN32__ */' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 73 | #enddef |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 74 | |
| 75 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 76 | |
| 77 | records = [] |
| 78 | |
| 79 | def FindOffset(funcName): |
| 80 | for (name, alias, offset) in records: |
| 81 | if name == funcName: |
| 82 | return offset |
| 83 | #endif |
| 84 | #endfor |
| 85 | return -1 |
| 86 | #enddef |
| 87 | |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 88 | # Find the size of the arguments on the stack for _stdcall name mangling |
| 89 | def FindStackSize(typeList): |
| 90 | result = 0 |
| 91 | for typ in typeList: |
| 92 | if typ == 'GLdouble' or typ == 'GLclampd': |
| 93 | result += 8; |
| 94 | else: |
| 95 | result += 4; |
| 96 | #endif |
| 97 | #endfor |
| 98 | return result |
| 99 | #enddef |
| 100 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 101 | def EmitFunction(name, returnType, argTypeList, argNameList, alias, offset): |
| 102 | argList = apiparser.MakeArgList(argTypeList, argNameList) |
| 103 | if alias != '': |
| 104 | dispatchName = alias |
| 105 | else: |
| 106 | dispatchName = name |
| 107 | #endif |
| 108 | |
| 109 | if offset < 0: |
| 110 | # try to find offset from alias name |
| 111 | assert dispatchName != '' |
| 112 | offset = FindOffset(dispatchName) |
| 113 | if offset == -1: |
| 114 | #print 'Cannot dispatch %s' % name |
| 115 | return |
| 116 | #endif |
| 117 | #endif |
| 118 | |
| 119 | # save this info in case we need to look up an alias later |
| 120 | records.append((name, dispatchName, offset)) |
| 121 | |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 122 | # Find the argument stack size for _stdcall name mangling |
| 123 | stackSize = FindStackSize(argTypeList) |
| 124 | |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 125 | # print the assembly code |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 126 | print 'ALIGNTEXT16' |
Kendall Bennett | 15c3734 | 2003-10-22 21:02:15 +0000 | [diff] [blame] | 127 | print "GLOBL_FN(GL_PREFIX(%s,%s@%s))" % (name, name, stackSize) |
| 128 | print "GL_PREFIX(%s,%s@%s):" % (name, name, stackSize) |
Brian Paul | 35883ce | 2002-06-11 01:26:58 +0000 | [diff] [blame] | 129 | print '\tMOV_L(CONTENT(GLNAME(_glapi_Dispatch)), EAX)' |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 130 | print "\tJMP(GL_OFFSET(_gloffset_%s))" % (dispatchName) |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 131 | print '' |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 132 | #enddef |
| 133 | |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 134 | PrintHead() |
Brian Paul | 6c0d72f | 2001-11-18 22:42:57 +0000 | [diff] [blame] | 135 | apiparser.ProcessSpecFile("APIspec", EmitFunction) |
Brian Paul | 5a8a6d9 | 2000-05-11 23:14:57 +0000 | [diff] [blame] | 136 | PrintTail() |