| #!/usr/bin/env python |
| |
| # $Id: glx86asm.py,v 1.5 2002/04/02 16:18:20 brianp 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(USE_MGL_NAMESPACE)' |
| print '#define GL_PREFIX(n) GLNAME(CONCAT(mgl,n))' |
| print '#else' |
| print '#define GL_PREFIX(n) 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)' |
| print '#define GLOBL_FN(x) GLOBL x ; .type x,@function' |
| print '#else' |
| print '#define GLOBL_FN(x) GLOBL x' |
| print '#endif' |
| print '' |
| 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 |
| |
| 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)) |
| |
| # print the assembly code |
| print 'ALIGNTEXT16' |
| print "GLOBL_FN(GL_PREFIX(%s))" % (name) |
| print "GL_PREFIX(%s):" % (name) |
| print '\tMOV_L(GLNAME(_glapi_Dispatch), EAX)' |
| print "\tJMP(GL_OFFSET(_gloffset_%s))" % (dispatchName) |
| print '' |
| |
| #enddef |
| |
| |
| |
| PrintHead() |
| apiparser.ProcessSpecFile("APIspec", EmitFunction) |
| PrintTail() |