# Copyright (c) 2001, Stanford University # All rights reserved. # # See the file LICENSE.txt for information on redistributing this software. import sys sys.path.append( "../glapi_parser" ) import apiutil keys = apiutil.GetDispatchedFunctions() apiutil.CopyrightC() print """ /* DO NOT EDIT - THIS FILE GENERATED BY THE glloader.py SCRIPT */ #include "cr_error.h" #include "cr_dll.h" #include "cr_spu.h" #include "cr_string.h" #include "cr_error.h" #include "cr_environment.h" #include <stdio.h> #if defined(Linux) || defined (SunOS) || defined(FreeBSD) #define SYSTEM_GL "libGL.so.1" typedef void (*glxfuncptr)(); extern glxfuncptr glxGetProcAddressARB( const GLubyte *name ); #else #error I don't know where your system's GL lives. Too bad.
print ");" else: print """) { CRDLMContextState *state = CURRENT_STATE(); instance->execute = executeFunc;""" # Add in the common code for adding the instance to the display list AddInstanceToList(" ") print '}' print '' # Now generate the functions that won't use the crdlm_add_to_list utility. # These all directly add their own instances to the current display list # themselves, without using the crdlm_add_to_list() function. keys = apiutil.GetDispatchedFunctions(sys.argv[3] + "/APIspec.txt") for func_name in keys: if apiutil.CanCompile(func_name): print "\n/*** %s ***/" % func_name # Auto-generate an appropriate DL function. First, functions # that go into the display list but that rely on state will # have to have their argument strings expanded, to take pointers # to that appropriate state. if whichfile == "headers": wrap_struct(func_name) elif not apiutil.FindSpecial("dlm", func_name): wrap_execute(func_name) wrap_compile(func_name) # Generate mapping between OPCODE and routines to be executed.
def GenerateEntrypoints(): #apiutil.CopyrightC() # Get sorted list of dispatched functions. # The order is very important - it must match cr_opcodes.h # and spu_dispatch_table.h print '%include "iprt/asmdefs.mac"' print "" print "%ifdef RT_ARCH_AMD64" print "extern glim" print "%else ; X86" print "extern glim" print "%endif" print "" keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for index in range(len(keys)): func_name = keys[index] if apiutil.Category(func_name) == "Chromium": continue if apiutil.Category(func_name) == "VBox": continue print "BEGINPROC_EXPORTED gl%s" % func_name print "%ifdef RT_ARCH_AMD64" print "\tmov \trax, qword glim+%d" % (8 * index) print "\tjmp \t[rax]" print "%else ; X86" print "\tmov \teax, dword glim+%d" % (4 * index) print "\tjmp \t[eax]" print "%endif" print "ENDPROC gl%s" % func_name print "" print ';' print '; Aliases' print ';' # Now loop over all the functions and take care of any aliases allkeys = apiutil.GetAllFunctions(sys.argv[1] + "/APIspec.txt") for func_name in allkeys: if "omit" in apiutil.ChromiumProps(func_name): continue if func_name in keys: # we already processed this function earlier continue # alias is the function we're aliasing alias = apiutil.Alias(func_name) if alias: # this dict lookup should never fail (raise an exception)! index = keys.index(alias) print "BEGINPROC_EXPORTED gl%s" % func_name print "%ifdef RT_ARCH_AMD64" print "\tmov \trax, qword glim+%d" % (8 * index) print "\tjmp \t[rax]" print "%else ; X86" print "\tmov \teax, dword glim+%d" % (4 * index) print "\tjmp \t[eax]" print "%endif" print "ENDPROC gl%s" % func_name print "" print ';' print '; No-op stubs' print ';' # Now generate no-op stub functions for func_name in allkeys: if "stub" in apiutil.ChromiumProps(func_name): print "BEGINPROC_EXPORTED gl%s" % func_name print "\tleave" print "\tret" print "ENDPROC gl%s" % func_name print ""
#include <stdio.h> static const CRPixelPackState defaultPacking = { 0, /* Row Length */ 0, /* Skip Rows */ 0, /* Skip Pixels */ 1, /* Alignment */ 0, /* Image Height */ 0, /* Skip Images */ GL_FALSE, /* Swap Bytes */ GL_FALSE /* LSB First */ }; """ keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt") ## We will use the state tracker diff infrastructure to push OpenGL ## state to the new GL stub upon resume. Once computedd differences, ## the Diff Dispatch Table is invoked to perform whatever action you ## want on the diffed state. In our case, we simply want to send ## the state to new GL stub. This script generates s Diff Dispatch ## Table that does just that. It's exceedingly simple for non-pixel ## functions. We need to hack a default packing when shipping pixel ## functions calls. for func_name in apiutil.AllSpecials( "packspu_diffpixel" ): return_type = apiutil.ReturnType(func_name) decl = apiutil.MakeDeclarationString(apiutil.Parameters(func_name)) print 'extern %s PACKSPU_APIENTRY packspu_Diff%s( %s );' % ( return_type, func_name, decl )
def GenerateEntrypoints(hacks=[]): """Emit code for all the OpenGL/Chromium entrypoints. hacks is an optional list of functions which are special cased. """ apiutil.CopyrightC() print('#define GL_GLEXT_PROTOTYPES') print('#include <stdio.h>') print('#include <stdlib.h>') print('#include <GL/gl.h>') print('#include "chromium.h"') print('#include "stub.h"') print('#include "dri_glx.h"') print('') print('#ifdef __GNUC__') print('# if (__GNUC__ << 16) + __GNUC_MINOR__ >= 0x40002') print('# pragma GCC diagnostic ignored "-Wunused-parameter"') print('# endif') print('#endif') # Get sorted list of dispatched functions. # The order is very important - it must match cr_opcodes.h # and spu_dispatch_table.h keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for index in range(len(keys)): func_name = keys[index] if apiutil.Category(func_name) == "Chromium": # this function is defined in stub.c continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) if func_name in hacks: print("/* hacked entrypoint: %s */" % func_name) if func_name == "TexImage3D": # Pretty common: internalformat is GLenum, not GLint print( "void glTexImage3D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels )" ) print("{") print( "\tglim.TexImage3D( target, level, (GLint) internalformat, width, height, depth, border, format, type, pixels );" ) print("}") elif func_name == "TexImage2D": # Pretty common: internalformat is GLenum, not GLint print( "void glTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels )" ) print("{") print( "\tglim.TexImage2D( target, level, (GLint) internalformat, width, height, border, format, type, pixels );" ) print("}") elif func_name == "TexImage1D": # Pretty common: internalformat is GLenum, not GLint print( "void glTexImage1D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels )" ) print("{") print( "\tglim.TexImage1D( target, level, (GLint) internalformat, width, border, format, type, pixels );" ) print("}") elif func_name == "EdgeFlagPointer": # second arg is GLboolean instead of GLvoid print( "void glEdgeFlagPointer( GLsizei stride, const GLboolean *pointer )" ) print("{") print("\tglim.EdgeFlagPointer( stride, pointer );") print("}") elif func_name == "ProgramParameters4fvNV": print( "void glProgramParameters4fvNV( GLenum target, GLuint index, GLuint num, const GLfloat *params )" ) print("{") print( "\tglim.ProgramParameters4fvNV( target, index, num, params );" ) print("}") elif func_name == "MultiDrawElementsEXT": print( "void glMultiDrawElementsEXT(GLenum mode, GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount)" ) print("{") print( "\tglim.MultiDrawElementsEXT(mode, count,type, indices, primcount);" ) print("}") elif func_name == "ProgramParameters4dvNV": print( "void glProgramParameters4dvNV( GLenum target, GLuint index, GLuint num, const GLdouble *params )" ) print("{") print( "\tglim.ProgramParameters4dvNV( target, index, num, params );" ) print("}") else: # the usual path print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") print("\t", end="") if return_type != "void": print("return ", end=" ") print("glim.%s(%s);" % (func_name, apiutil.MakeCallString(params))) print("}") print("") print('/*') print('* Aliases') print('*/') # Now loop over all the functions and take care of any aliases allkeys = apiutil.GetAllFunctions(sys.argv[1] + "/APIspec.txt") for func_name in allkeys: if "omit" in apiutil.ChromiumProps(func_name): continue if func_name in keys: # we already processed this function earlier continue # alias is the function we're aliasing alias = apiutil.Alias(func_name) if alias: if func_name in hacks: print("/* hacked entrypoint: %s */" % func_name) if func_name == "MultiDrawArrays": print( "void glMultiDrawArrays( GLenum mode, const GLint *first, const GLsizei *count, GLsizei primcount )" ) print("{") print( "\tglim.MultiDrawArraysEXT( mode, (GLint*)first, (GLsizei*)count, primcount );" ) print("}") elif func_name == "BufferData": print( "void glBufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)" ) print("{") print("\tglim.BufferDataARB(target, size, data, usage);") print("}") elif func_name == "BufferSubData": print( "void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)" ) print("{") print( "\tglim.BufferSubDataARB(target, offset, size, data);") print("}") elif func_name == "GetBufferSubData": print( "void glGetBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, GLvoid *data)" ) print("{") print( "\tglim.GetBufferSubDataARB(target, offset, size, data);" ) print("}") else: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") print("\t", end="") if return_type != "void": print("return ", end=" ") print("glim.%s(%s);" % (alias, apiutil.MakeCallString(params))) print("}") print("") print('/*') print('* No-op stubs') print('*/') # Now generate no-op stub functions for func_name in allkeys: if "stub" in apiutil.ChromiumProps(func_name): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print("%s VBOXGLTAG(gl%s)(%s);" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("") print("%s VBOXGLTAG(gl%s)(%s)" % (return_type, func_name, apiutil.MakeDeclarationString(params))) print("{") if return_type != "void": print("return (%s) 0" % return_type) print("}") print("")
apiutil.CopyrightC() print """ /* DO NOT EDIT - THIS FILE AUTOMATICALLY GENERATED BY expando.py SCRIPT */ #include <stdio.h> #include "cr_error.h" #include "cr_spu.h" #include "cr_dlm.h" #include "expandospu.h" """ allFunctions = [] generatedFunctions = [] for func_name in apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt"): if apiutil.FindSpecial("expando", func_name): allFunctions.append(func_name) elif apiutil.CanCompile(func_name) or apiutil.SetsClientState(func_name): generatedFunctions.append(func_name) allFunctions.append(func_name) for func_name in generatedFunctions: params = apiutil.Parameters(func_name) return_type = apiutil.ReturnType(func_name) basicCallString = apiutil.MakeCallString(params) declarationString = apiutil.MakeDeclarationString(params) dlmCallString = basicCallString chromiumProps = apiutil.ChromiumProps(func_name) needClientState = 0
def GenerateEntrypoints(): apiutil.CopyrightC() print '#include "chromium.h"' print '#include "stub.h"' print '' print '#define NAKED __declspec(naked)' print '#define UNUSED(x) ((void)(x))' print '' # Get sorted list of dispatched functions. # The order is very important - it must match cr_opcodes.h # and spu_dispatch_table.h keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt") for index in range(len(keys)): func_name = keys[index] if apiutil.Category(func_name) == "Chromium": continue if apiutil.Category(func_name) == "VBox": continue return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" print "\t__asm jmp [glim.%s]" % func_name for (name, type, vecSize) in params: print "\tUNUSED( %s );" % name print "}" print "" print '/*' print '* Aliases' print '*/' # Now loop over all the functions and take care of any aliases allkeys = apiutil.GetAllFunctions(sys.argv[1] + "/APIspec.txt") for func_name in allkeys: if "omit" in apiutil.ChromiumProps(func_name): continue if func_name in keys: # we already processed this function earlier continue # alias is the function we're aliasing alias = apiutil.Alias(func_name) if alias: return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" print "\t__asm jmp [glim.%s]" % alias for (name, type, vecSize) in params: print "\tUNUSED( %s );" % name print "}" print "" print '/*' print '* No-op stubs' print '*/' # Now generate no-op stub functions for func_name in allkeys: if "stub" in apiutil.ChromiumProps(func_name): return_type = apiutil.ReturnType(func_name) params = apiutil.Parameters(func_name) print "NAKED %s cr_gl%s( %s )" % ( return_type, func_name, apiutil.MakeDeclarationString(params)) print "{" if return_type != "void": print "return (%s) 0" % return_type print "}" print ""
def GenerateEntrypoints(): apiutil.CopyrightC() # Get sorted list of dispatched functions. # The order is very important - it must match cr_opcodes.h # and spu_dispatch_table.h keys = apiutil.GetDispatchedFunctions("../glapi_parser/APIspec.txt") for index in range(len(keys)): func_name = keys[index] if apiutil.Category(func_name) == "Chromium": continue print "\t.align 4" print ".globl gl%s" % func_name print "\t.type gl%s,@function" % func_name print "gl%s:" % func_name print "\tmovl glim+%d, %%eax" % (4*index) print "\tjmp *%eax" print "" print '/*' print '* Aliases' print '*/' # Now loop over all the functions and take care of any aliases allkeys = apiutil.GetAllFunctions("../glapi_parser/APIspec.txt") for func_name in allkeys: if "omit" in apiutil.ChromiumProps(func_name): continue if func_name in keys: # we already processed this function earlier continue # alias is the function we're aliasing alias = apiutil.Alias(func_name) if alias: # this dict lookup should never fail (raise an exception)! index = keys.index(alias) print "\t.align 4" print ".globl gl%s" % func_name print "\t.type gl%s,@function" % func_name print "gl%s:" % func_name print "\tmovl glim+%d, %%eax" % (4*index) print "\tjmp *%eax" print "" print '/*' print '* No-op stubs' print '*/' # Now generate no-op stub functions for func_name in allkeys: if "stub" in apiutil.ChromiumProps(func_name): print "\t.align 4" print ".globl gl%s" % func_name print "\t.type gl%s,@function" % func_name print "gl%s:" % func_name print "\tleave" print "\tret" print ""
apiutil.CopyrightC() print """ /* DO NOT EDIT - THIS FILE AUTOMATICALLY GENERATED BY expando.py SCRIPT */ #include <stdio.h> #include "cr_error.h" #include "cr_spu.h" #include "cr_dlm.h" #include "expandospu.h" """ allFunctions = [] generatedFunctions = [] for func_name in apiutil.GetDispatchedFunctions( "../../glapi_parser/APIspec.txt"): if apiutil.FindSpecial("expando", func_name): allFunctions.append(func_name) elif apiutil.CanCompile(func_name) or apiutil.SetsClientState(func_name): generatedFunctions.append(func_name) allFunctions.append(func_name) for func_name in generatedFunctions: params = apiutil.Parameters(func_name) return_type = apiutil.ReturnType(func_name) basicCallString = apiutil.MakeCallString(params) declarationString = apiutil.MakeDeclarationString(params) dlmCallString = basicCallString chromiumProps = apiutil.ChromiumProps(func_name) needClientState = 0