-
- def visit_pointer(self, pointer, lvalue, rvalue):
- print ' const Trace::Array *__a%s = dynamic_cast<const Trace::Array *>(&%s);' % (pointer.id, rvalue)
- print ' if (__a%s) {' % (pointer.id)
- try:
- self.visit(pointer.type, '%s[0]' % (lvalue,), '*__a%s->values[0]' % (pointer.id,))
- finally:
- print ' }'
-
-
- def visit_handle(self, handle, lvalue, rvalue):
- print " __%s_map[static_cast<%s>(%s)] = %s;" % (handle.name, handle.type, rvalue, lvalue)
- print ' if (verbosity >= 2)'
- print ' std::cout << "%s " << static_cast<%s>(%s) << " -> " << %s << "\\n";' % (handle.name, handle.type, rvalue, lvalue)
-
- def visit_blob(self, blob, lvalue, rvalue):
- pass
-
- def visit_string(self, string, lvalue, rvalue):
- pass
-
-
-
-def retrace_function(function):
- print 'static void retrace_%s(Trace::Call &call) {' % function.name
- success = True
- for arg in function.args:
- arg_type = ConstRemover().visit(arg.type)
- #print ' // %s -> %s' % (arg.type, arg_type)
- print ' %s %s;' % (arg_type, arg.name)
- rvalue = 'call.arg(%u)' % (arg.index,)
- lvalue = arg.name
- try:
- ValueExtractor().visit(arg_type, lvalue, rvalue)
- except NotImplementedError:
- success = False
- print ' %s = 0; // FIXME' % arg.name
- if not success:
- print ' std::cerr << "warning: unsupported call %s\\n";' % function.name
- print ' return;'
- arg_names = ", ".join([arg.name for arg in function.args])
- if function.type is not stdapi.Void:
- print ' %s __result;' % (function.type)
- print ' __result = %s(%s);' % (function.name, arg_names)
- else:
- print ' %s(%s);' % (function.name, arg_names)
- for arg in function.args:
- if arg.output:
- arg_type = ConstRemover().visit(arg.type)
- rvalue = 'call.arg(%u)' % (arg.index,)
- lvalue = arg.name
- try:
- ValueWrapper().visit(arg_type, lvalue, rvalue)
- except NotImplementedError:
- print ' // FIXME: %s' % arg.name
- if function.type is not stdapi.Void:
- rvalue = '*call.ret'
- lvalue = '__result'
- try:
- ValueWrapper().visit(function.type, lvalue, rvalue)
- except NotImplementedError:
- print ' // FIXME: result'
- print '}'
- print
-
-
-def retrace_functions(functions):
- for function in functions:
- if function.sideeffects:
- retrace_function(function)
-
- print 'static bool retrace_call(Trace::Call &call) {'
- for function in functions:
- if not function.sideeffects:
- print ' if (call.name == "%s") {' % function.name
- print ' return true;'
- print ' }'
- print
- print ' if (verbosity >=1 ) {'
- print ' std::cout << call;'
- print ' std::cout.flush();'
- print ' };'
- print
- for function in functions:
- if function.sideeffects:
- print ' if (call.name == "%s") {' % function.name
- print ' retrace_%s(call);' % function.name
- print ' return true;'
+
+ if function.name == "glEnd":
+ print ' glretrace::insideGlBeginEnd = false;'
+
+ if function.name == 'memcpy':
+ print ' if (!dest || !src || !n) return;'
+
+ Retracer.call_function(self, function)
+
+ # Error checking
+ if function.name == "glBegin":
+ print ' glretrace::insideGlBeginEnd = true;'
+ elif function.name.startswith('gl'):
+ # glGetError is not allowed inside glBegin/glEnd
+ print ' if (!glretrace::benchmark && !glretrace::insideGlBeginEnd) {'
+ print ' glretrace::checkGlError(call);'
+ if function.name in ('glProgramStringARB', 'glProgramStringNV'):
+ print r' GLint error_position = -1;'
+ print r' glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &error_position);'
+ print r' if (error_position != -1) {'
+ print r' const char *error_string = (const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB);'
+ print r' std::cerr << call.no << ": warning: " << error_string << "\n";'
+ print r' }'
+ if function.name == 'glCompileShader':
+ print r' GLint compile_status = 0;'
+ print r' glGetShaderiv(shader, GL_COMPILE_STATUS, &compile_status);'
+ print r' if (!compile_status) {'
+ print r' GLint info_log_length = 0;'
+ print r' glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_log_length);'
+ print r' GLchar *infoLog = new GLchar[info_log_length];'
+ print r' glGetShaderInfoLog(shader, info_log_length, NULL, infoLog);'
+ print r' std::cerr << call.no << ": warning: " << infoLog << "\n";'
+ print r' delete [] infoLog;'
+ print r' }'
+ if function.name == 'glLinkProgram':
+ print r' GLint link_status = 0;'
+ print r' glGetProgramiv(program, GL_LINK_STATUS, &link_status);'
+ print r' if (!link_status) {'
+ print r' GLint info_log_length = 0;'
+ print r' glGetProgramiv(program, GL_INFO_LOG_LENGTH, &info_log_length);'
+ print r' GLchar *infoLog = new GLchar[info_log_length];'
+ print r' glGetProgramInfoLog(program, info_log_length, NULL, infoLog);'
+ print r' std::cerr << call.no << ": warning: " << infoLog << "\n";'
+ print r' delete [] infoLog;'
+ print r' }'
+ if function.name == 'glCompileShaderARB':
+ print r' GLint compile_status = 0;'
+ print r' glGetObjectParameterivARB(shaderObj, GL_OBJECT_COMPILE_STATUS_ARB, &compile_status);'
+ print r' if (!compile_status) {'
+ print r' GLint info_log_length = 0;'
+ print r' glGetObjectParameterivARB(shaderObj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &info_log_length);'
+ print r' GLchar *infoLog = new GLchar[info_log_length];'
+ print r' glGetInfoLogARB(shaderObj, info_log_length, NULL, infoLog);'
+ print r' std::cerr << call.no << ": warning: " << infoLog << "\n";'
+ print r' delete [] infoLog;'
+ print r' }'
+ if function.name == 'glLinkProgramARB':
+ print r' GLint link_status = 0;'
+ print r' glGetObjectParameterivARB(programObj, GL_OBJECT_LINK_STATUS_ARB, &link_status);'
+ print r' if (!link_status) {'
+ print r' GLint info_log_length = 0;'
+ print r' glGetObjectParameterivARB(programObj, GL_OBJECT_INFO_LOG_LENGTH_ARB, &info_log_length);'
+ print r' GLchar *infoLog = new GLchar[info_log_length];'
+ print r' glGetInfoLogARB(programObj, info_log_length, NULL, infoLog);'
+ print r' std::cerr << call.no << ": warning: " << infoLog << "\n";'
+ print r' delete [] infoLog;'
+ print r' }'
+ if function.name in ('glMapBuffer', 'glMapBufferARB', 'glMapBufferRange', 'glMapNamedBufferEXT', 'glMapNamedBufferRangeEXT'):
+ print r' if (!__result) {'
+ print r' std::cerr << call.no << ": warning: failed to map buffer\n";'
+ print r' }'
+ if function.name in ('glGetAttribLocation', 'glGetAttribLocationARB'):
+ print r' GLint __orig_result = call.ret->toSInt();'
+ print r' if (__result != __orig_result) {'
+ print r' std::cerr << call.no << ": warning vertex attrib location mismatch " << __orig_result << " -> " << __result << "\n";'
+ print r' }'
+ if function.name in ('glCheckFramebufferStatus', 'glCheckFramebufferStatusEXT', 'glCheckNamedFramebufferStatusEXT'):
+ print r' GLint __orig_result = call.ret->toSInt();'
+ print r' if (__orig_result == GL_FRAMEBUFFER_COMPLETE &&'
+ print r' __result != GL_FRAMEBUFFER_COMPLETE) {'
+ print r' std::cerr << call.no << ": incomplete framebuffer (" << __result << ")\n";'
+ print r' }'