Ejemplo n.º 1
0
        CRDBGPTR_CHECKZ(pState->pWritebackPtr);
        CRDBGPTR_CHECKZ(pState->pReturnPtr);
    
        /*crDebug(\"Unpacking opcode \%d\", *pState->pbOpcodes);*/
#ifdef CR_UNPACK_DEBUG_PREV_OPCODES
        g_VBoxDbgCrPrevOpcode = *pState->pbOpcodes;
#endif
        switch( *pState->pbOpcodes )
        {""")

#
# Emit switch cases for all unextended opcodes
#
for func_name in keys:
    if "pack" in apiutil.ChromiumProps(func_name):
        print('\t\t\tcase %s:' % apiutil.OpcodeName(func_name))
        if not apiutil.OpcodeName(func_name) in nodebug_opcodes:
            print("""
#ifdef CR_UNPACK_DEBUG_LAST_OPCODES
                if (i==(pState->cOpcodes-1))
#endif
#if defined(CR_UNPACK_DEBUG_OPCODES) || defined(CR_UNPACK_DEBUG_LAST_OPCODES)
                crDebug("Unpack: %s");
#endif """ % apiutil.OpcodeName(func_name))
        print('\t\t\t\tcrUnpack%s(pState); \n\t\t\t\tbreak;' % func_name)

print("""       
            case CR_EXTEND_OPCODE:
                #ifdef CR_UNPACK_DEBUG_OPCODES 
                    crUnpackExtendDbg(pState);
                #else
Ejemplo n.º 2
0
apiutil.CopyrightC()

print("""
#include "cr_debugopcodes.h"
#include <stdio.h>
""")

print("""void crDebugOpcodes( FILE *fp, unsigned char *ptr, unsigned int num_opcodes )
{
\tunsigned int i;
\tfor (i = 0; i < num_opcodes; i++)
\t{
\t\tswitch(*(ptr--))
\t\t{
""")

keys = apiutil.GetDispatchedFunctions(sys.argv[1]+"/APIspec.txt")
keys.sort()

for func_name in keys:
	if "pack" in apiutil.ChromiumProps(func_name):
		print('\t\tcase %s:' % apiutil.OpcodeName( func_name ))
		print('\t\t\tfprintf(fp, "%s\\n"); ' % apiutil.OpcodeName( func_name ))
		print( '\t\t\tbreak;')

print("""
\t\t}
\t}
}
""")
Ejemplo n.º 3
0
def PrintFunction(func_name, extSuffix, num_coords, argtype, do_swapped,
                  do_count, do_vector):
    """
	Generate all the functions named crPackVertex[234][dfis][v]BBOX() and
	crPackVertex[234][dfis][v]BBOX_COUNT().
	We also handle glVertexAttrib*ARB.
	Note: func_name should not have an ARB suffix.
	"""

    if do_count:
        countSuffix = "_COUNT"
    else:
        countSuffix = ""

    if do_swapped:
        swapSuffix = "SWAP"
    else:
        swapSuffix = ""

    if func_name[0:12] == "VertexAttrib":
        isVertexAttrib = 1
    else:
        isVertexAttrib = 0

    if argtype[0] == "N":
        normalized = 1
    else:
        normalized = 0

    if argtype == "b" or argtype == "Nb":
        vector_type = "GLbyte"
    elif argtype == "ub" or argtype == "Nub":
        vector_type = "GLubyte"
    elif argtype == "s" or argtype == "Ns":
        vector_type = "GLshort"
    elif argtype == "us" or argtype == "Nus":
        vector_type = "GLushort"
    elif argtype == "i" or argtype == "Ni":
        vector_type = "GLint"
    elif argtype == "ui" or argtype == "Nui":
        vector_type = "GLuint"
    elif argtype == "f":
        vector_type = "GLfloat"
    elif argtype == "d":
        vector_type = "GLdouble"
    else:
        print "type is %s" % argtype
        abort()

    if do_vector:
        if isVertexAttrib:
            func_name = 'VertexAttrib%d%sv' % (num_coords, argtype)
        else:
            func_name = 'Vertex%d%sv' % (num_coords, argtype)

    params = apiutil.Parameters(func_name + extSuffix)

    print 'void PACK_APIENTRY crPack%sBBOX%s%s( %s )' % (
        func_name + extSuffix, countSuffix, swapSuffix,
        apiutil.MakeDeclarationString(params))
    print '{'

    if do_vector:
        # vector version
        packet_length = num_coords * apiutil.sizeof(vector_type)
        if isVertexAttrib:
            packet_length += 4  # for index
        if packet_length % 4 != 0:
            packet_length += 2

    else:
        # non-vector
        packet_length = apiutil.PacketLength(params)
        if isVertexAttrib:
            packet_length += 0  # for index
        if packet_length % 4 != 0:
            packet_length += 2

    print "\tGET_PACKER_CONTEXT(pc);"
    print "\tunsigned char *data_ptr;"

    if normalized:
        if argtype == "Nb":
            t = "B"
        elif argtype == "Ni":
            t = "I"
        elif argtype == "Nui":
            t = "UI"
        elif argtype == "Nub":
            t = "UB"
        elif argtype == "Ns":
            t = "S"
        elif argtype == "Nus":
            t = "US"
        else:
            abort()
        if do_vector:
            print "\tCREATE_%dD_VFLOATS_%s_NORMALIZED();" % (num_coords, t)
        else:
            print "\tCREATE_%dD_FLOATS_%s_NORMALIZED();" % (num_coords, t)
    else:
        if do_vector:
            print "\tCREATE_%dD_VFLOATS();" % num_coords
        else:
            print "\tCREATE_%dD_FLOATS();" % num_coords

    print "\tGET_BUFFERED%s_POINTER( pc, %d );" % (countSuffix, packet_length)

    # Bounding box code
    if isVertexAttrib:
        print "\tif (pc->updateBBOX && index == 0)"
    else:
        print "\tif (pc->updateBBOX)"
    print "\t{"
    if num_coords < 4:
        print "\t\tUPDATE_%dD_BBOX();" % num_coords
    else:
        print "\t\tUPDATE_3D_BBOX();"
    print "\t}"

    if isVertexAttrib:
        print "\tif (index > 0) {"
        t = argtype
        print "\t\tpc->current.c.vertexAttrib.%s%d[index] = data_ptr + 4;" % (
            t, num_coords)
        print "\t\tpc->current.attribsUsedMask |= (1 << index);"
        if do_count:
            print "\t\tpc->current.vtx_count--;"

        print "\t}"

        fname = func_name + extSuffix
        if do_vector:
            # use non-vector opcode
            opcode = apiutil.OpcodeName(func_name[:-1] + extSuffix)
        else:
            opcode = apiutil.OpcodeName(func_name + extSuffix)
    counter = 0

    if do_vector:
        if isVertexAttrib:
            if do_swapped:
                print "\tWRITE_DATA( 0, GLuint, SWAP32(index) );"
            else:
                print "\tWRITE_DATA( 0, GLuint, index );"
            counter += 4
            argname = params[1][0]  # skip 'index' parameter
        else:
            argname = params[0][0]

        for index in range(num_coords):
            print WriteData(counter, vector_type, "%s[%d]" % (argname, index),
                            do_swapped)
            counter += apiutil.sizeof(vector_type)

        if isVertexAttrib:
            if do_vector == 2:
                # this is a bit of a hack
                print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(
                    func_name + "ARB")
            else:
                print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(
                    func_name[:-1] + "ARB")
        else:
            print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(
                func_name[:-1])
    else:
        for index in range(0, len(params)):
            (name, type, vecSize) = params[index]
            print WriteData(counter, type, name, do_swapped)
            counter += apiutil.sizeof(type)

        if isVertexAttrib:
            print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(func_name +
                                                                   "ARB")
        else:
            print "\tWRITE_OPCODE( pc, %s );" % apiutil.OpcodeName(func_name)

    print '}\n'
Ejemplo n.º 4
0
	unpack_opcodes = (const unsigned char *)opcodes;
	cr_unpackData = (const unsigned char *)data;

	for (i = 0 ; i < num_opcodes ; i++)
	{
		/*crDebug(\"Unpacking opcode \%d\", *unpack_opcodes);*/
		switch( *unpack_opcodes )
		{"""

#
# Emit switch cases for all unextended opcodes
#
for func_name in keys:
    if "pack" in apiutil.ChromiumProps(func_name):
        print '\t\t\tcase %s:' % apiutil.OpcodeName(func_name),
        print 'crUnpack%s(); break;' % func_name

print """		
			case CR_EXTEND_OPCODE: crUnpackExtend(); break;
			default:
				crError( "Unknown opcode: %d", *unpack_opcodes );
				break;
		}
		unpack_opcodes--;
	}
}"""

#
# Emit unpack functions for extended opcodes, non-special functions only.
#
Ejemplo n.º 5
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')
Ejemplo n.º 6
0
print "/* DO NOT EDIT - THIS FILE GENERATED BY THE opcodes.py SCRIPT */"
print ""
print "#ifndef CR_OPCODES_H"
print "#define CR_OPCODES_H"
print ""

keys = apiutil.GetDispatchedFunctions(sys.argv[1] + "/APIspec.txt")
assert len(keys) > 0

print "/* Functions with no return value and input-only parameters */"
print "typedef enum {"

enum_index = 0
for func in keys:
    if "pack" in apiutil.ChromiumProps(func):
        print "\t%s = %d," % (apiutil.OpcodeName(func), enum_index)
        enum_index = enum_index + 1

if enum_index > 255:
    # This would have saved Mike some grief if it had been here earlier.
    print >> sys.stderr, "You have more than 255 opcodes!  You've been adding functions to"
    print >> sys.stderr, "glapi_parser/APIspec!  Each new function you add"
    print >> sys.stderr, "gets an opcode assigned to it.  Fortunately for you, we have"
    print >> sys.stderr, "an ``extend'' opcode.  Please mark the function as"
    print >> sys.stderr, "'extpack' in APIspec so as to keep the main opcode pool"
    print >> sys.stderr, "less than 255!  THIS IS A CATASTROPHIC FAILURE, and I WILL NOT CONTINUE!"
    print >> sys.stderr, "I'm putting an error in the generated header file so you won't miss"
    print >> sys.stderr, "this even if you're doing a 'make -k.'"
    print "#error -- more than 255 opcodes!"
    sys.exit(-1)
print "\tCR_EXTEND_OPCODE=%d" % enum_index