예제 #1
0
def MakeNormalCall(return_type, func_name, params, counter_init=0):
    counter = counter_init
    copy_of_params = params[:]

    for i in range(0, len(params)):
        (name, type, vecSize) = params[i]
        if apiutil.IsPointer(copy_of_params[i][1]):
            params[i] = ('NULL', type, vecSize)
            copy_of_params[i] = (copy_of_params[i][0], 'void', 0)
            if not "get" in apiutil.Properties(func_name):
                print('\tcrError( "%s needs to be special cased!" );' %
                      func_name)
        else:
            print("\t%s %s = %s;" % (copy_of_params[i][1], name,
                                     ReadData(counter, copy_of_params[i][1])))
        counter += apiutil.sizeof(copy_of_params[i][1])

    if ("get" in apiutil.Properties(func_name)):
        FindReturnPointer(return_type, params)
        FindWritebackPointer(return_type, params)

    if return_type != "void":
        print("\t(void)", end=" ")
    else:
        print("\t", end="")
    print("pState->pDispatchTbl->%s(%s);" %
          (func_name, apiutil.MakeCallStringForDispatcher(params)))
예제 #2
0
def PrintBodies(func_name,f,no_special, gentables):
	#print "func_name = %s  no_special = %d" % (func_name, no_special)
	if no_special == 1:
		if apiutil.FindSpecial( "packertest", func_name ):
			return

	if not allfuncs:
		if not apiutil.HasPackOpcode(func_name):
			return

	pointers_ok = 0

	return_type = apiutil.ReturnType(func_name)
	params = apiutil.Parameters(func_name)

	if "get" in apiutil.Properties(func_name):
		pointers_ok = 1

	if func_name == 'Writeback':
		pointers_ok = 1

	#print "func_name = %s pointers_ok = %d no_special = %d" % (func_name, pointers_ok,no_special)
	#print params
	if gentables == 1:
		PrintTableFunc( func_name, params, pointers_ok ,f)
	else:
		PrintFunc( func_name, params, pointers_ok ,f)
예제 #3
0
def wrap_struct(functionName):
    params = apiutil.Parameters(functionName)
    argstring = apiutil.MakeDeclarationString(params)
    extendedArgstring = argstring
    props = apiutil.Properties(functionName)
    if "useclient" in props or "pixelstore" in props:
        extendedArgstring += ", CRClientState *c"

    # We'll keep track of all the parameters that require pointers.
    # They'll require special handling later.
    (pointers, pointername, pointerarg, pointertype, pointersize,
     pointercomment) = GetPointerInfo(functionName)

    # Start writing the header
    print 'struct instance%s {' % (functionName)
    print '	DLMInstanceList *next;'
    print '	DLMInstanceList *stateNext;'
    print '	int cbInstance;'
    print '	VBoxDLOpCode iVBoxOpCode;'
    print '	void (DLM_APIENTRY *execute)(DLMInstanceList *instance, SPUDispatchTable *dispatchTable);'
    for (name, type, vecSize) in params:
        # Watch out for the word "const" (which should be ignored)
        # and for types that end in "*" (which are pointers and need
        # special treatment)
        words = type.split()
        if words[0] == 'const':
            words = words[1:]
        if words[0] != "void":
            print '	%s %s;' % (' '.join(words), name)

    # If any argument was a pointer, we need a special pointer data
    # array.  The pointer data will be stored into this array, and
    # references to the array will be generated as parameters.
    if len(pointers) == 1:
        if pointersize == None:
            print "	/* Oh no - pointer parameter %s found, but no pointer class specified and can't guess */" % pointername
        else:
            if pointersize == 'special':
                print '	%s %s[1];%s' % (pointertype, pointerarg,
                                        pointercomment)
            else:
                print '	%s %s[%s];%s' % (pointertype, pointerarg, pointersize,
                                         pointercomment)
    elif len(pointers) > 1:
        print '	%s %s[1];%s' % (pointertype, pointerarg, pointercomment)

    print '};'

    # Pointers only happen with instances
    if len(pointers) > 1 or (len(pointers) == 1 and pointersize == 'special'):
        print 'int crdlm_pointers_%s(struct instance%s *instance, %s);' % (
            functionName, functionName, extendedArgstring)

    # See if the GL function must sometimes allow passthrough even
    # if the display list is open
    if "checklist" in apiutil.ChromiumProps(functionName):
        print 'int crdlm_checklist_%s(%s);' % (functionName, argstring)

    return
예제 #4
0
def wrap_compile(functionName):
    params = apiutil.Parameters(functionName)
    return_type = apiutil.ReturnType(functionName)
    # Make sure the return type is void.  It's nonsensical to compile
    # an element with any other return type.
    if return_type != 'void':
        print '/* Nonsense: DL function %s has a %s return type?!? */' % (
            functionName, return_type)

    # Define a structure to hold all the parameters.  Note that the
    # top parameters must exactly match the DLMInstanceList structure
    # in include/cr_dlm.h, or everything will break horribly.
    # Start off by getting all the pointer info we could ever use
    # from the parameters
    (pointers, pointername, pointerarg, pointertype, pointersize,
     pointercomment) = GetPointerInfo(functionName)

    # Finally, the compile wrapper.  This one will diverge strongly
    # depending on whether or not there are pointer parameters.
    callstring = apiutil.MakeCallString(params)
    argstring = apiutil.MakeDeclarationString(params)
    props = apiutil.Properties(functionName)
    if "useclient" in props or "pixelstore" in props:
        callstring += ", c"
        argstring += ", CRClientState *c"
    print 'void DLM_APIENTRY crDLMCompile%s(%s)' % (functionName, argstring)
    print '{'
    print '    CRDLMContextState *state = CURRENT_STATE();'
    print '    struct instance%s *instance;' % (functionName)

    # The calling SPU is supposed to verify that the element is supposed to be
    # compiled before it is actually compiled; typically, this is done based
    # on whether a glNewList has been executed more recently than a glEndList.
    # But some functions are dual-natured, sometimes being compiled, and sometimes
    # being executed immediately.  We can check for this here.
    if "checklist" in apiutil.ChromiumProps(functionName):
        print '    if (crDLMCheckList%s(%s))' % (
            functionName, apiutil.MakeCallString(params))
        print '    {'
        print '        crdlm_error(__LINE__, __FILE__, GL_INVALID_OPERATION,'
        print '            "this instance of function %s should not be compiled");' % functionName
        print '        return;'
        print '    }'

    if len(pointers) > 1 or pointersize == 'special':
        # Pass NULL, to just allocate space
        print '    instance = crCalloc(sizeof(struct instance%s) + crdlm_pointers_%s(NULL, %s));' % (
            functionName, functionName, callstring)
    else:
        print '    instance = crCalloc(sizeof(struct instance%s));' % (
            functionName)
    print '    if (!instance)'
    print '    {'
    print '        crdlm_error(__LINE__, __FILE__, GL_OUT_OF_MEMORY,'
    print '            "out of memory adding %s to display list");' % (
        functionName)
    print '        return;'
    print '    }'

    # Put in the fields that must always exist
    print '    instance->execute = execute%s;' % functionName

    # Apply all the simple (i.e. non-pointer) parameters
    for index in range(len(params)):
        if index not in pointers:
            name = params[index][0]
            print '    instance->%s = %s;' % (name, name)

    # We need to know instance size in bytes in order to save its state later.
    print '    instance->cbInstance = sizeof(struct instance%s);' % functionName

    # Set OPCODE.
    print '    instance->iVBoxOpCode = VBOX_DL_OPCODE_%s;' % functionName

    # If there's a pointer parameter, apply it.
    if len(pointers) == 1:

        print '    if (%s == NULL)' % (params[pointers[0]][0])
        print '        instance->%s = NULL;' % (params[pointers[0]][0])
        print '    else'
        print '        instance->%s = instance->%s;' % (params[pointers[0]][0],
                                                        pointerarg)

        if pointersize == 'special':
            print '    instance->cbInstance += crdlm_pointers_%s(instance, %s);' % (
                functionName, callstring)
        else:
            print '    crMemcpy((void *)instance->%s, (void *) %s, %s*sizeof(%s));' % (
                params[pointers[0]][0], params[pointers[0]][0], pointersize,
                pointertype)
    elif len(pointers) == 2:
        # this seems to work
        print '    instance->cbInstance += crdlm_pointers_%s(instance, %s);' % (
            functionName, callstring)
    elif len(pointers) > 2:
        print "#error don't know how to handle pointer parameters for %s" % (
            functionName)

    # Add the element to the current display list
    AddInstanceToList('    ')
    # If the element is a state-changing element, add it to the current state list
    if apiutil.SetsTrackedState(functionName):
        AddInstanceToStateList('    ')
    print '}'
예제 #5
0
print("""
/* DO NOT EDIT - THIS FILE AUTOMATICALLY GENERATED BY server_dispatch.py SCRIPT */
#include "cr_spu.h"
#include "chromium.h"
#include "cr_error.h"
#include "server_dispatch.h"
#include "server.h"
#include "cr_unpack.h"

CRCurrentStatePointers crServerCurrent;
""")

for func_name in apiutil.AllSpecials(sys.argv[1] + "/../state_tracker/state"):
    params = apiutil.Parameters(func_name)
    if (apiutil.FindSpecial("server", func_name)
            or "get" in apiutil.Properties(func_name)):
        continue

    wrap = apiutil.GetCategoryWrapper(func_name)
    if wrap:
        print('#if defined(CR_%s)' % wrap)
    print('void SERVER_DISPATCH_APIENTRY crServerDispatch%s(%s)' %
          (func_name, apiutil.MakeDeclarationString(params)))
    print('{')
    print('\tcrState%s(%s);' % (func_name, apiutil.MakeCallString(params)))
    print('\tcr_server.head_spu->dispatch_table.%s(%s);' %
          (func_name, apiutil.MakeCallString(params)))
    print('}')
    if wrap:
        print('#endif')
예제 #6
0
# Generate the list of functions, starting with those coded into
# the module
for (returnValue, name, parameters) in additionalFunctions:
    if mode == 'header':
        print "extern %s %s(%s);" % (returnValue, name, parameters)
    elif mode == 'defs':
        print "%s" % name

# Continue with functions that are auto-generated.

if mode == 'header':
    print
    print "/* auto-generated compilation functions begin here */"

for func_name in keys:
    props = apiutil.Properties(func_name)
    # We're interested in intercepting all calls that:
    #   - can be put into a display list (i.e. "not ("nolist" in props)")
    #   - change client-side state that affects saving DL elements (i.e. "setclient" in props)

    if apiutil.CanCompile(func_name):
        params = apiutil.Parameters(func_name)
        argstring = apiutil.MakeDeclarationString(params)
        if "useclient" in props or "pixelstore" in props:
            argstring = argstring + ", CRClientState *c"

        if mode == 'header':
            print 'extern void DLM_APIENTRY crDLMCompile%s(%s);' % (func_name,
                                                                    argstring)
        elif mode == 'defs':
            print "crDLMCompile%s" % func_name
예제 #7
0
apiutil.CopyrightC()


print """
#ifndef HIDDENLINE_SPU_PROTO_H
#define HIDDENLINE_SPU_PROTO_H 1

"""

keys = apiutil.GetDispatchedFunctions("../../glapi_parser/APIspec.txt")

# Determine which functions to ignore
ignore_functions = []
for func_name in keys:
	if ("get" in apiutil.Properties(func_name) or
		"setclient" in apiutil.Properties(func_name) or
		"useclient" in apiutil.Properties(func_name) or
		apiutil.Category(func_name) == "Chromium" or
		apiutil.Category(func_name) == "GL_chromium"):
		ignore_functions.append(func_name)

specials = apiutil.AllSpecials( "hiddenline" ) + apiutil.AllSpecials( "hiddenline_pixel" )

# emit prototypes
for func_name in specials:
	return_type = apiutil.ReturnType(func_name)
	params = apiutil.Parameters(func_name)
	print 'extern %s HIDDENLINESPU_APIENTRY hiddenlinespu_%s(%s);' % (return_type, func_name, apiutil.MakeDeclarationString(params))

예제 #8
0
    'GetTexGeniv': 'SWAP32',
    'GetTexLevelParameterfv': 'SWAPFLOAT',
    'GetTexLevelParameteriv': 'SWAP32',
    'GetTexParameterfv': 'SWAPFLOAT',
    'GetTexParameteriv': 'SWAP32'
}

keys = apiutil.GetDispatchedFunctions("../../glapi_parser/APIspec.txt")

for func_name in keys:
    params = apiutil.Parameters(func_name)
    return_type = apiutil.ReturnType(func_name)
    if apiutil.FindSpecial("packspu", func_name):
        continue

    if "get" in apiutil.Properties(func_name):
        print '%s PACKSPU_APIENTRY packspu_%s( %s )' % (
            return_type, func_name, apiutil.MakeDeclarationString(params))
        print '{'
        print '\tGET_THREAD(thread);'
        print '\tint writeback = 1;'
        if return_type != 'void':
            print '\t%s return_val = (%s) 0;' % (return_type, return_type)
            params.append(("&return_val", "foo", 0))
        if (func_name in easy_swaps.keys() and easy_swaps[func_name] != '0'
            ) or func_name in simple_funcs or func_name in hard_funcs.keys():
            print '\tunsigned int i;'
        print '\tif (!(pack_spu.thread[0].netServer.conn->actual_network))'
        print '\t{'
        print '\t\tcrError( "packspu_%s doesn\'t work when there\'s no actual network involved!\\nTry using the simplequery SPU in your chain!" );' % func_name
        print '\t}'
예제 #9
0
for func_name in keys:
    if ("pack" in apiutil.ChromiumProps(func_name)
            or "extpack" in apiutil.ChromiumProps(func_name)
            or apiutil.NonVectorFunction(func_name) != ''
            or apiutil.FindSpecial('packer', func_name)):

        # OK, generate a crPackFooBar() prototype for this function
        return_type = apiutil.ReturnType(func_name)
        args = apiutil.Parameters(func_name)
        if return_type != 'void':
            if apiutil.IsPointer(return_type):
                args.append(("return_value", return_type, 0))
            else:
                args.append(("return_value", return_type + "*", 0))
        elif "pixelstore" in apiutil.Properties(func_name):
            args.append(("packstate", "const CRPixelPackState *", 0))

        if "get" in apiutil.Properties(func_name):
            args.append(("writeback", "int *", 0))

        print 'void PACK_APIENTRY crPack%s( %s );' % (
            func_name, apiutil.MakeDeclarationString(args))
        print 'void PACK_APIENTRY crPack%sSWAP( %s );' % (
            func_name, apiutil.MakeDeclarationString(args))

# Now generate special BBOX, COUNT, SWAP variations on the glVertex and
# glVertexAttrib functions.
for func_name in keys:
    if (func_name[0:6] == "Vertex"
            and "pervertex" in apiutil.Properties(func_name)
예제 #10
0
def PrintFunc(func_name, params, is_swapped, can_have_pointers):
    """Emit a packer function."""
    if is_swapped:
        print('void PACK_APIENTRY crPack%sSWAP(%s)' %
              (func_name,
               apiutil.MakeDeclarationStringWithContext(
                   'CR_PACKER_CONTEXT', params)))
    else:
        print('void PACK_APIENTRY crPack%s(%s)' %
              (func_name,
               apiutil.MakeDeclarationStringWithContext(
                   'CR_PACKER_CONTEXT', params)))
    print('{')
    print('\tCR_GET_PACKER_CONTEXT(pc);')

    # Save original function name
    orig_func_name = func_name

    # Convert to a non-vector version of the function if possible
    func_name = apiutil.NonVectorFunction(func_name)
    if not func_name:
        func_name = orig_func_name

    # Check if there are any pointer parameters.
    # That's usually a problem so we'll emit an error function.
    nonVecParams = apiutil.Parameters(func_name)
    bail_out = 0
    for (name, type, vecSize) in nonVecParams:
        if apiutil.IsPointer(type) and vecSize == 0 and not can_have_pointers:
            bail_out = 1
    if bail_out:
        for (name, type, vecSize) in nonVecParams:
            print('\t(void)%s;' % (name))
        print('\tcrError ( "%s needs to be special cased %d %d!");' %
              (func_name, vecSize, can_have_pointers))
        print('\t(void) pc;')
        print('}')
        # XXX we should really abort here
        return

    if "extpack" in apiutil.ChromiumProps(func_name):
        is_extended = 1
    else:
        is_extended = 0

    print("\tunsigned char *data_ptr;")
    print('\t(void) pc;')
    #if func_name == "Enable" or func_name == "Disable":
    #   print "\tCRASSERT(!pc->buffer.geometry_only); /* sanity check */"

    for index in range(0, len(params)):
        (name, type, vecSize) = params[index]
        if vecSize > 0 and func_name != orig_func_name:
            print("    if (!%s) {" % name)
            # Know the reason for this one, so avoid the spam.
            if orig_func_name != "SecondaryColor3fvEXT":
                print("        crDebug(\"App passed NULL as %s for %s\");" %
                      (name, orig_func_name))
            print("        return;")
            print("    }")

    packet_length = apiutil.PacketLength(nonVecParams)

    if packet_length == 0 and not is_extended:
        print("\tCR_GET_BUFFERED_POINTER_NO_ARGS(pc);")
    elif func_name[:9] == "Translate" or func_name[:5] == "Color":
        # XXX WTF is the purpose of this?
        if is_extended:
            packet_length += 8
        print("\tCR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, %d, GL_TRUE);" %
              packet_length)
    else:
        if is_extended:
            packet_length += 8
        print("\tCR_GET_BUFFERED_POINTER(pc, %d);" % packet_length)
    UpdateCurrentPointer(func_name)

    if is_extended:
        counter = 8
        print(WriteData(0, 'GLint', packet_length, is_swapped))
        print(
            WriteData(4, 'GLenum', apiutil.ExtendedOpcodeName(func_name),
                      is_swapped))
    else:
        counter = 0

    # Now emit the WRITE_() macros for all parameters
    for index in range(0, len(params)):
        (name, type, vecSize) = params[index]
        # if we're converting a vector-valued function to a non-vector func:
        if vecSize > 0 and func_name != orig_func_name:
            ptrType = apiutil.PointerType(type)
            for i in range(0, vecSize):
                print(
                    WriteData(counter + i * apiutil.sizeof(ptrType), ptrType,
                              "%s[%d]" % (name, i), is_swapped))
            # XXX increment counter here?
        else:
            print(WriteData(counter, type, name, is_swapped))
            if apiutil.IsPointer(type):
                counter += apiutil.PointerSize()
            else:
                counter += apiutil.sizeof(type)

    # finish up
    if is_extended:
        print("\tWRITE_OPCODE(pc, CR_EXTEND_OPCODE);")
    else:
        print("\tWRITE_OPCODE(pc, %s);" % apiutil.OpcodeName(func_name))

    if "get" in apiutil.Properties(func_name):
        print('\tCR_CMDBLOCK_CHECK_FLUSH(pc);')

    print('\tCR_UNLOCK_PACKER_CONTEXT(pc);')
    print('}\n')
예제 #11
0
#
# See the file LICENSE.txt for information on redistributing this software.

import sys

sys.path.append("../../glapi_parser")
import apiutil

apiutil.CopyrightC()

print """#include <stdio.h>
#include "cr_spu.h"
#include "cr_glstate.h"
#include "state/cr_stateerror.h"
#include "simplequeryspu.h"

"""

specials = ["WindowCreate", "CreateContext"]

apiutil.GetAllFunctions("../../glapi_parser/APIspec.txt")
keys = apiutil.GetDispatchedFunctions()

print 'SPUNamedFunctionTable _cr_simplequery_table[] = {'
for func_name in keys:
    if not func_name in specials and "get" in apiutil.Properties(func_name):
        print '\t{ "%s", (SPUGenericFunction) crState%s },' % (func_name,
                                                               func_name)
print "\t{ NULL, NULL }"
print "};"