load "file"; load "array"; var gl_h = file_read(parameters.srcfile); gl_h =~ s/,\s*\n/, /g; write(<:> : // mod_gl.c: Auto-generated by gen_gl.spl : : #include "GL/gl.h" : : #include "spl.h" : #include "compat.h" : : /** : * OpenGL Module : * : * This module provides an interface to the OpenGL API. : */ ); function void_to_spl(t) { return [ retexpr: "0" ]; } function ANYFLOAT_to_spl(t) { return [ callprefix: "$t ret = ", retexpr: "SPL_NEW_FLOAT(ret)" ]; } var GLfloat_to_spl = ANYFLOAT_to_spl; var GLclampf_to_spl = ANYFLOAT_to_spl; var GLdouble_to_spl = ANYFLOAT_to_spl; var GLclampd_to_spl = ANYFLOAT_to_spl; function ANYINT_to_spl(t) { return [ callprefix: "$t ret = ", retexpr: "SPL_NEW_INT(ret)" ]; } var GLenum_to_spl = ANYINT_to_spl; var GLsizei_to_spl = ANYINT_to_spl; var GLbitfield_to_spl = ANYINT_to_spl; var GLbyte_to_spl = ANYINT_to_spl; var GLshort_to_spl = ANYINT_to_spl; var GLint_to_spl = ANYINT_to_spl; var GLubyte_to_spl = ANYINT_to_spl; var GLushort_to_spl = ANYINT_to_spl; var GLuint_to_spl = ANYINT_to_spl; function spl_to_ANYFLOAT(n, t) { return [ getargs: "\t$t arg$n = spl_clib_get_float(task);\n" ]; } var spl_to_GLfloat = spl_to_ANYFLOAT; var spl_to_GLclampf = spl_to_ANYFLOAT; var spl_to_GLdouble = spl_to_ANYFLOAT; var spl_to_GLclampd = spl_to_ANYFLOAT; function spl_to_GLboolean(n, t) { return [ getargs: "\t$t arg$n = spl_clib_get_int(task) ? GL_TRUE : GL_FALSE;\n" ]; } function spl_to_ANYINT(n, t) { return [ getargs: "\t$t arg$n = spl_clib_get_int(task);\n" ]; } var spl_to_GLenum = spl_to_ANYINT; var spl_to_GLsizei = spl_to_ANYINT; var spl_to_GLbitfield = spl_to_ANYINT; var spl_to_GLbyte = spl_to_ANYINT; var spl_to_GLshort = spl_to_ANYINT; var spl_to_GLint = spl_to_ANYINT; var spl_to_GLubyte = spl_to_ANYINT; var spl_to_GLushort = spl_to_ANYINT; var spl_to_GLuint = spl_to_ANYINT; var fdata; var skipped_handlers; foreach[] fdecl (gl_h =~ /^GLAPI.*?\)/Amg) { fdecl =~ s/\s+/ /g; fdecl =~ s/\s*([()])\s*/$1/g; fdecl =~ s/\s+(\**)\s*[^\s,()[\]]+(\[\d+\]|)([,)])/$1$2$3/g; fdecl =~ s/(GL|)API(ENTRY|)\s+//g; if (fdecl =~ /\d.v/ or fdecl =~ /MESA/) continue; var cdecl = fdecl; fdecl =~ s/(const)\s+/$1_/g; fdecl =~ s/\[(\d+)\]/_a$1/g; fdecl =~ s/\s+\*/_p/g; fdecl =~ s/^(\S+)\s+(\S+)\((.*)\)/$3/; var types = [ $1 ], name = $2; while (fdecl =~ s/([^\s,]+)//) if ($1 ~!= "void") push types, $1; var tid = array_join(types, ":"); if (not declared fdata[tid]) fdata[tid] = [ types: types, cdecl: cdecl, flist: [] ]; push fdata[tid].flist, name; } foreach[] ftype (fdata) { var funcname = "handler__" ~ array_join(ftype.types, "__"); function ctype(typename) { typename =~ s/_p$/*/; typename =~ s/_p\*$/**/; typename =~ s/_a(\d+)$/[$1]/; typename =~ s/^(const)_/$1 /; return typename; } var snippets = [ getargs: "", callprefix: "", postcall: "", retexpr: "" ]; var snippet_functions; var skip_this = 0; foreach i (ftype.types) if (i == 0) { var t = "${ftype.types[i]}_to_spl"; push t, ftype.types[i]; push snippet_functions, t; } else { var t = "spl_to_${ftype.types[i]}"; push t, i; push t, ftype.types[i]; push snippet_functions, t; } foreach[] f (snippet_functions) { if (not defined [/][f]) { if (not skip_this) write("\n// SKIP: $funcname\n"); write("// Not found: $f\n"); skip_this = 1; continue; } foreach i ([/][f](@f)) snippets[i] ~= $@[i]; } if (skip_this) skipped_handlers[funcname] = 1; else write(<:> : : static struct spl_node *$funcname(struct spl_task *task UNUSED, void *data) : { : ${ctype(ftype.types[0])}(*funcp)(, ${ctype(ftype.types[i])}) = data; $snippets.getargs : ${snippets.callprefix}funcp(, arg$i); $snippets.postcall : return $snippets.retexpr; : } ); } write(<:> : : /** : * The following OpenGL functions are wrapped by this module: : * [^(]+)\(/I; b =~ /\s(?P<_b>[^(]+)\(/I; return _a ~> _b; }); ?> : * $f; : */ : // manual function_list; : : struct spl_node *handler_glEnum(struct spl_task *task, void UNUSED(*data)) : { : int ret; : char *arg = spl_clib_get_string(task); : if (!strcmp(arg, "${e[1]}")) : ret = ${e[1]}; : else : return 0; : return SPL_NEW_INT(ret); : } : : void SPL_ABI(spl_mod_gl_init)(struct spl_vm *vm, struct spl_module UNUSED(*mod), int UNUSED(restore)) : { : spl_clib_reg(vm, "glEnum", handler_glEnum, 0); :// spl_clib_reg(vm, "$f", $funcname, $f); : spl_clib_reg(vm, "$f", $funcname, $f); : } : :void SPL_ABI(spl_mod_gl_done)(struct spl_vm UNUSED(*vm), struct spl_module UNUSED(*mod)) :{ : return; :} );