From 7f0f4aab2a307626c13b860179f46017480f7985 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 25 Sep 2014 12:47:32 -0700 Subject: emulator/opengl/emugen: Introduce helper macros. This patch introduces two helper macros in the generated decoder to make its source code slightly more readable (DEBUG and SET_LASCALL). Change-Id: I6659fe69a5533e5194d8db5f1882abaf1a5daee5 --- emulator/opengl/host/tools/emugen/ApiGen.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'emulator') diff --git a/emulator/opengl/host/tools/emugen/ApiGen.cpp b/emulator/opengl/host/tools/emugen/ApiGen.cpp index e7f6d0b8a..8b2548bf9 100644 --- a/emulator/opengl/host/tools/emugen/ApiGen.cpp +++ b/emulator/opengl/host/tools/emugen/ApiGen.cpp @@ -756,6 +756,21 @@ int ApiGen::genDecoderImpl(const std::string &filename) fprintf(fp, "#include \n\n"); fprintf(fp, "typedef unsigned int tsize_t; // Target \"size_t\", which is 32-bit for now. It may or may not be the same as host's size_t when emugen is compiled.\n\n"); + // helper macros + fprintf(fp, + "#ifdef DEBUG_PRINTOUT\n" + "# define DEBUG(...) fprintf(stderr, __VA_ARGS__)\n" + "#else\n" + "# define DEBUG(...) ((void)0)\n" + "#endif\n\n"); + + fprintf(fp, + "#ifdef CHECK_GLERROR\n" + "# define SET_LASTCALL(name) sprintf(lastCall, #name)\n" + "#else\n" + "# define SET_LASTCALL(name) ((void)0)\n" + "#endif\n\n"); + // helper templates fprintf(fp, "using namespace emugl;\n\n"); @@ -817,9 +832,8 @@ int ApiGen::genDecoderImpl(const std::string &filename) fprintf(fp, "this"); // add a context to the call } } else if (pass == PASS_DebugPrint) { - fprintf(fp, "#ifdef DEBUG_PRINTOUT\n"); fprintf(fp, - "\t\t\tfprintf(stderr,\"%s(%%p): %s(%s)\\n\", stream", + "\t\t\tDEBUG(\"%s(%%p): %s(%s)\\n\", stream", m_basename.c_str(), e->name().c_str(), printString.c_str()); @@ -1010,9 +1024,6 @@ int ApiGen::genDecoderImpl(const std::string &filename) pass == PASS_DebugPrint) { fprintf(fp, ");\n"); } - if (pass == PASS_DebugPrint) { - fprintf(fp, "#endif\n"); - } if (pass == PASS_TmpBuffAlloc) { if (!e->retval().isVoid() && !e->retval().isPointer()) { @@ -1045,9 +1056,7 @@ int ApiGen::genDecoderImpl(const std::string &filename) } // pass; fprintf(fp, "\t\t\t}\n"); - fprintf(fp, "#ifdef CHECK_GL_ERROR\n"); - fprintf(fp, "\t\t\tsprintf(lastCall, \"%s\");\n", e->name().c_str()); - fprintf(fp, "#endif\n"); + fprintf(fp, "\t\t\tSET_LASTCALL(\"%s\");\n", e->name().c_str()); fprintf(fp, "\t\t\tbreak;\n"); delete [] tmpBufOffset; -- cgit v1.2.3