python 3 compatible
This commit is contained in:
parent
7266fe2d47
commit
642330e22c
1 changed files with 94 additions and 90 deletions
|
|
@ -128,28 +128,28 @@ def gen_functions_header(entries, prefix_name, verbatim, filename, with_args):
|
|||
"""
|
||||
prefix_name = prefix_name.upper()
|
||||
|
||||
print "// Auto-generated with: %s" % banner_command(sys.argv)
|
||||
print "// DO NOT EDIT THIS FILE"
|
||||
print ""
|
||||
print "#ifndef %s_FUNCTIONS_H" % prefix_name
|
||||
print "#define %s_FUNCTIONS_H" % prefix_name
|
||||
print ""
|
||||
print("// Auto-generated with: %s" % banner_command(sys.argv))
|
||||
print("// DO NOT EDIT THIS FILE")
|
||||
print("")
|
||||
print("#ifndef %s_FUNCTIONS_H" % prefix_name)
|
||||
print("#define %s_FUNCTIONS_H" % prefix_name)
|
||||
print("")
|
||||
for line in verbatim:
|
||||
print line
|
||||
print(line)
|
||||
|
||||
print "#define LIST_%s_FUNCTIONS(X) \\" % prefix_name
|
||||
print("#define LIST_%s_FUNCTIONS(X) \\" % prefix_name)
|
||||
for entry in entries:
|
||||
if with_args:
|
||||
print " X(%s, %s, (%s), (%s)) \\" % \
|
||||
print(" X(%s, %s, (%s), (%s)) \\" % \
|
||||
(entry.return_type, entry.func_name, entry.parameters,
|
||||
entry.call)
|
||||
entry.call))
|
||||
else:
|
||||
print " X(%s, %s, (%s)) \\" % \
|
||||
(entry.return_type, entry.func_name, entry.parameters)
|
||||
print(" X(%s, %s, (%s)) \\" % \
|
||||
(entry.return_type, entry.func_name, entry.parameters))
|
||||
|
||||
print ""
|
||||
print ""
|
||||
print "#endif // %s_FUNCTIONS_H" % prefix_name
|
||||
print("")
|
||||
print("")
|
||||
print("#endif // %s_FUNCTIONS_H" % prefix_name)
|
||||
|
||||
|
||||
|
||||
|
|
@ -199,10 +199,10 @@ def gen_translator(entries):
|
|||
"glProgramUniform3ui": 1,
|
||||
"glProgramUniform4ui": 1,
|
||||
"glBindVertexBuffer": 1,
|
||||
};
|
||||
}
|
||||
translator_nocontext_fail_codes = {
|
||||
"glClientWaitSync" : "GL_WAIT_FAILED",
|
||||
};
|
||||
}
|
||||
def needExternC(entry):
|
||||
if translator_needexternc.has_key(entry.func_name):
|
||||
return "extern \"C\" "
|
||||
|
|
@ -210,14 +210,14 @@ def gen_translator(entries):
|
|||
return ""
|
||||
def get_fail_code(entry):
|
||||
if translator_nocontext_fail_codes.has_key(entry.func_name):
|
||||
return translator_nocontext_fail_codes[entry.func_name];
|
||||
return translator_nocontext_fail_codes[entry.func_name]
|
||||
else:
|
||||
return "0"
|
||||
def gen_cxt_getter(entry):
|
||||
if (entry.return_type == "void"):
|
||||
print " GET_CTX_V2();"
|
||||
print(" GET_CTX_V2();")
|
||||
else:
|
||||
print " GET_CTX_V2_RET(%s);" % get_fail_code(entry)
|
||||
print(" GET_CTX_V2_RET(%s);" % get_fail_code(entry))
|
||||
|
||||
def gen_validations_custom_impl(entry):
|
||||
isGen = entry.func_name.startswith("glGen")
|
||||
|
|
@ -231,14 +231,14 @@ def gen_translator(entries):
|
|||
if entry.return_type == "void":
|
||||
return "SET_ERROR_IF(%s,%s)" % (condition, glerr);
|
||||
else:
|
||||
return "RET_AND_SET_ERROR_IF(%s,%s,%s)" % (condition, glerr, get_fail_code(entry));
|
||||
return "RET_AND_SET_ERROR_IF(%s,%s,%s)" % (condition, glerr, get_fail_code(entry))
|
||||
|
||||
if (isGen or isDelete) and ("n" in entry.varnames):
|
||||
print " %s;" % mySetError("n < 0", "GL_INVALID_VALUE");
|
||||
print(" %s;" % mySetError("n < 0", "GL_INVALID_VALUE"))
|
||||
if (isBufferOp and hasTargetArg):
|
||||
print " %s;" % mySetError("!GLESv2Validate::bufferTarget(ctx, target)", "GL_INVALID_ENUM");
|
||||
print(" %s;" % mySetError("!GLESv2Validate::bufferTarget(ctx, target)", "GL_INVALID_ENUM"))
|
||||
if translator_custom_pre.has_key(entry.func_name):
|
||||
print translator_custom_pre[entry.func_name],
|
||||
print(translator_custom_pre[entry.func_name],)
|
||||
|
||||
def gen_call_ret(entry):
|
||||
globalNameTypes = {
|
||||
|
|
@ -262,53 +262,53 @@ def gen_translator(entries):
|
|||
needsShareGroup = True
|
||||
|
||||
if needsShareGroup:
|
||||
print " if (ctx->shareGroup().get()) {"
|
||||
print(" if (ctx->shareGroup().get()) {")
|
||||
for key in zip(entry.vartypes, entry.varnames):
|
||||
vartype, varname = key
|
||||
if globalNames.has_key(key):
|
||||
print " const GLuint %s = ctx->shareGroup()->getGlobalName(%s, %s);" % (globalNames[key], globalNameTypes[key], varname)
|
||||
print(" const GLuint %s = ctx->shareGroup()->getGlobalName(%s, %s);" % (globalNames[key], globalNameTypes[key], varname))
|
||||
|
||||
globalCall = ", ".join(map(lambda k: globalNames.get(k, k[1]), zip(entry.vartypes, entry.varnames)))
|
||||
|
||||
if needsShareGroup and translator_custom_share_processing.has_key(entry.func_name):
|
||||
print translator_custom_share_processing[entry.func_name],
|
||||
print(translator_custom_share_processing[entry.func_name])
|
||||
|
||||
if (entry.return_type == "void"):
|
||||
if (needsShareGroup):
|
||||
print " ",
|
||||
print(" "),
|
||||
|
||||
if not translator_no_passthrough.has_key(entry.func_name):
|
||||
print " ctx->dispatcher().%s(%s);" % (entry.func_name, globalCall)
|
||||
print(" ctx->dispatcher().%s(%s);" % (entry.func_name, globalCall))
|
||||
|
||||
if needsShareGroup:
|
||||
print " }"
|
||||
print(" }")
|
||||
if translator_custom_post.has_key(entry.func_name):
|
||||
print translator_custom_post[entry.func_name];
|
||||
print(translator_custom_post[entry.func_name])
|
||||
else:
|
||||
if (needsShareGroup):
|
||||
print " ",
|
||||
print(" "),
|
||||
if not translator_no_passthrough.has_key(entry.func_name):
|
||||
print " %s %s = ctx->dispatcher().%s(%s);" % (entry.return_type, entry.func_name + "RET", entry.func_name, globalCall)
|
||||
print(" %s %s = ctx->dispatcher().%s(%s);" % (entry.return_type, entry.func_name + "RET", entry.func_name, globalCall))
|
||||
else:
|
||||
print " %s %s = %s" % (entry.return_type, entry_func_name + "RET", get_fail_code(entry))
|
||||
print(") %s %s = %s" % (entry.return_type, entry_func_name + "RET", get_fail_code(entry)))
|
||||
|
||||
if translator_custom_post.has_key(entry.func_name):
|
||||
print translator_custom_post[entry.func_name];
|
||||
print(translator_custom_post[entry.func_name])
|
||||
|
||||
print " return %s;" % (entry.func_name + "RET");
|
||||
print(" return %s;" % (entry.func_name + "RET"))
|
||||
if needsShareGroup:
|
||||
print " } else return %s;" % (get_fail_code(entry))
|
||||
print(" } else return %s;" % (get_fail_code(entry)))
|
||||
|
||||
print "// Auto-generated with: %s" % banner_command(sys.argv)
|
||||
print "// This file is best left unedited."
|
||||
print "// Try to make changes through gen_translator in gen-entries.py,"
|
||||
print "// and/or parcel out custom functionality in separate code."
|
||||
print("// Auto-generated with: %s" % banner_command(sys.argv))
|
||||
print("// This file is best left unedited.")
|
||||
print("// Try to make changes through gen_translator in gen-entries.py,")
|
||||
print("// and/or parcel out custom functionality in separate code.")
|
||||
for entry in entries:
|
||||
print "%sGL_APICALL %s GL_APIENTRY %s(%s) {" % (needExternC(entry), entry.return_type, entry.func_name, entry.parameters)
|
||||
gen_cxt_getter(entry);
|
||||
gen_validations_custom_impl(entry);
|
||||
gen_call_ret(entry);
|
||||
print "}\n"
|
||||
print("%sGL_APICALL %s GL_APIENTRY %s(%s) {" % (needExternC(entry), entry.return_type, entry.func_name, entry.parameters))
|
||||
gen_cxt_getter(entry)
|
||||
gen_validations_custom_impl(entry)
|
||||
gen_call_ret(entry)
|
||||
print("}\n")
|
||||
|
||||
def gen_dll_wrapper(entries, prefix_name, verbatim, filename):
|
||||
"""Generate a C source file that contains functions that act as wrappers
|
||||
|
|
@ -322,77 +322,77 @@ def gen_dll_wrapper(entries, prefix_name, verbatim, filename):
|
|||
|
||||
ENTRY_PREFIX = "__dll_"
|
||||
|
||||
print "// Auto-generated with: %s" % banner_command(sys.argv)
|
||||
print "// DO NOT EDIT THIS FILE"
|
||||
print ""
|
||||
print "#include <dlfcn.h>"
|
||||
print("// Auto-generated with: %s" % banner_command(sys.argv))
|
||||
print("// DO NOT EDIT THIS FILE")
|
||||
print("")
|
||||
print("#include <dlfcn.h>")
|
||||
for line in verbatim:
|
||||
print line
|
||||
print(line)
|
||||
|
||||
print ""
|
||||
print "///"
|
||||
print "/// W R A P P E R P O I N T E R S"
|
||||
print "///"
|
||||
print ""
|
||||
print("")
|
||||
print("///")
|
||||
print("/// W R A P P E R P O I N T E R S")
|
||||
print("///")
|
||||
print("")
|
||||
for entry in entries:
|
||||
ptr_name = ENTRY_PREFIX + entry.func_name
|
||||
print "static %s (*%s)(%s) = 0;" % \
|
||||
(entry.return_type, ptr_name, entry.parameters)
|
||||
print("static %s (*%s)(%s) = 0;" % \
|
||||
(entry.return_type, ptr_name, entry.parameters))
|
||||
|
||||
print ""
|
||||
print "///"
|
||||
print "/// W R A P P E R F U N C T I O N S"
|
||||
print "///"
|
||||
print ""
|
||||
print("")
|
||||
print("///")
|
||||
print("/// W R A P P E R F U N C T I O N S")
|
||||
print("///")
|
||||
print("")
|
||||
|
||||
for entry in entries:
|
||||
print "%s %s(%s) {" % \
|
||||
(entry.return_type, entry.func_name, entry.parameters)
|
||||
print ("%s %s(%s) {" % \
|
||||
(entry.return_type, entry.func_name, entry.parameters))
|
||||
ptr_name = ENTRY_PREFIX + entry.func_name
|
||||
if entry.return_type != "void":
|
||||
print " return %s(%s);" % (ptr_name, entry.call)
|
||||
print(" return %s(%s);" % (ptr_name, entry.call))
|
||||
else:
|
||||
print " %s(%s);" % (ptr_name, entry.call)
|
||||
print "}\n"
|
||||
print(" %s(%s);" % (ptr_name, entry.call))
|
||||
print("}\n")
|
||||
|
||||
print ""
|
||||
print "///"
|
||||
print "/// I N I T I A L I Z A T I O N F U N C T I O N"
|
||||
print "///"
|
||||
print ""
|
||||
print("")
|
||||
print("///")
|
||||
print("/// I N I T I A L I Z A T I O N F U N C T I O N")
|
||||
print("///")
|
||||
print("")
|
||||
|
||||
print "int %s_dynlink_init(void* lib) {" % prefix_name
|
||||
print("int %s_dynlink_init(void* lib) {" % prefix_name)
|
||||
for entry in entries:
|
||||
ptr_name = ENTRY_PREFIX + entry.func_name
|
||||
print " %s = (%s(*)(%s))dlsym(lib, \"%s\");" % \
|
||||
print(" %s = (%s(*)(%s))dlsym(lib, \"%s\");" % \
|
||||
(ptr_name,
|
||||
entry.return_type,
|
||||
entry.parameters,
|
||||
entry.func_name)
|
||||
print " if (!%s) return -1;" % ptr_name
|
||||
print " return 0;"
|
||||
print "}"
|
||||
entry.func_name))
|
||||
print(" if (!%s) return -1;" % ptr_name)
|
||||
print(" return 0;")
|
||||
print("}")
|
||||
|
||||
|
||||
def gen_windows_def_file(entries):
|
||||
"""Generate a windows DLL .def file. |entries| is a list of Entry instances.
|
||||
"""
|
||||
print "EXPORTS"
|
||||
print("EXPORTS")
|
||||
for entry in entries:
|
||||
print " %s" % entry.func_name
|
||||
print(" %s" % entry.func_name)
|
||||
|
||||
|
||||
def gen_unix_sym_file(entries):
|
||||
"""Generate an ELF linker version file. |entries| is a list of Entry
|
||||
instances.
|
||||
"""
|
||||
print "VERSION {"
|
||||
print "\tglobal:"
|
||||
print("VERSION {")
|
||||
print("\tglobal:")
|
||||
for entry in entries:
|
||||
print "\t\t%s;" % entry.func_name
|
||||
print "\tlocal:"
|
||||
print "\t\t*;"
|
||||
print "};"
|
||||
print("\t\t%s;" % entry.func_name)
|
||||
print("\tlocal:")
|
||||
print("\t\t*;")
|
||||
print("};")
|
||||
|
||||
def gen_symbols(entries, underscore):
|
||||
"""Generate a list of symbols from |entries|, a list of Entry instances.
|
||||
|
|
@ -403,7 +403,7 @@ def gen_symbols(entries, underscore):
|
|||
if underscore:
|
||||
prefix = "_"
|
||||
for entry in entries:
|
||||
print "%s%s" % (prefix, entry.func_name)
|
||||
print("%s%s" % (prefix, entry.func_name))
|
||||
|
||||
def parse_file(filename, lines, mode):
|
||||
"""Generate one of possible outputs from |filename|. |lines| must be a list
|
||||
|
|
@ -413,7 +413,9 @@ def parse_file(filename, lines, mode):
|
|||
entries, prefix_name, verbatim, errors = parse_entries_file(lines)
|
||||
if errors:
|
||||
for error in errors:
|
||||
print >> sys.stderr, "ERROR: %s:%s" % (filename, error)
|
||||
print("ERROR: %s:%s" % (filename, error))
|
||||
#FIXME
|
||||
#print >> sys.stderr, "ERROR: %s:%s" % (filename, error)
|
||||
sys.exit(1)
|
||||
|
||||
if not prefix_name:
|
||||
|
|
@ -466,7 +468,9 @@ parser.add_argument("file", help=".entries file path")
|
|||
args = parser.parse_args()
|
||||
|
||||
if not args.mode:
|
||||
print >> sys.stderr, "ERROR: Please use --mode=<name>, see --help."
|
||||
print("ERROR: Please use --mode=<name>, see --help.")
|
||||
#FIXME
|
||||
#print >> sys.stderr, "ERROR: Please use --mode=<name>, see --help."
|
||||
sys.exit(1)
|
||||
|
||||
if args.output:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue