From d0dc1ddf4a9678714c88aca05883592f04f6c37f Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 25 Sep 2014 12:56:12 -0700 Subject: emulator/opengl/emugen: Move pointer increment out of case statements. Minor patch that ensures that the pointer/position increment all happen at one place, instead of being replicated in each case statement. In other words, the generated code used to look like: switch (opcode) { case OP_someOperation1: { ... ptr += *(uint32_t)(ptr + 4); pos += *(uint32_t)(ptr + 4); break; } case OP_someOperation2: { ... ptr += *(uint32_t)(ptr + 4); pos += *(uint32_t)(ptr + 4); break; } ... default: { unknownOpcode = true; } Now it looks like: switch (opcode) { case OP_someOperation1: { ... break; } case OP_someOperation2: { ... break; } ... default: { unknownOpcode = true; } if (!unknownOpcode) { ptr += packetLen; pos += packetLen; } Which is cleaner. Also change the type of |opcode| and |packetLen| to uint32_t and size_t respectively. + Minor formatting changes to indentation. Change-Id: If0002fe18a24b9ce6691e3e3cd3e102d1e00d4c9 --- emulator/opengl/host/tools/emugen/ApiGen.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/emulator/opengl/host/tools/emugen/ApiGen.cpp b/emulator/opengl/host/tools/emugen/ApiGen.cpp index 8b2548b..cd4ede8 100644 --- a/emulator/opengl/host/tools/emugen/ApiGen.cpp +++ b/emulator/opengl/host/tools/emugen/ApiGen.cpp @@ -786,8 +786,8 @@ int ApiGen::genDecoderImpl(const std::string &filename) \tchar lastCall[256] = {0}; \n\ #endif \n\ \twhile ((len - pos >= 8) && !unknownOpcode) { \n\ -\t\tint opcode = *(int *)ptr; \n\ -\t\tunsigned int packetLen = *(int *)(ptr + 4);\n\ +\t\tuint32_t opcode = *(uint32_t *)ptr; \n\ +\t\tsize_t packetLen = *(uint32_t *)(ptr + 4);\n\ \t\tif (len - pos < packetLen) return pos; \n\ \t\tswitch(opcode) {\n"); @@ -804,8 +804,7 @@ int ApiGen::genDecoderImpl(const std::string &filename) printString += ""; // TODO - add for return value; - fprintf(fp, "\t\t\tcase OP_%s:\n", e->name().c_str()); - fprintf(fp, "\t\t\t{\n"); + fprintf(fp, "\t\tcase OP_%s: {\n", e->name().c_str()); bool totalTmpBuffExist = false; std::string totalTmpBuffOffset = "0"; @@ -1049,15 +1048,12 @@ int ApiGen::genDecoderImpl(const std::string &filename) if (totalTmpBuffExist) { fprintf(fp, "\t\t\tstream->flush();\n"); } - - fprintf(fp, "\t\t\tpos += *(uint32_t *)(ptr + 4);\n"); - fprintf(fp, "\t\t\tptr += *(uint32_t *)(ptr + 4);\n"); } } // pass; - fprintf(fp, "\t\t\t}\n"); fprintf(fp, "\t\t\tSET_LASTCALL(\"%s\");\n", e->name().c_str()); fprintf(fp, "\t\t\tbreak;\n"); + fprintf(fp, "\t\t}\n"); delete [] tmpBufOffset; } @@ -1070,6 +1066,11 @@ int ApiGen::genDecoderImpl(const std::string &filename) fprintf(fp, "\tif (err) fprintf(stderr, \"%s Error: 0x%%X in %%s\\n\", err, lastCall);\n", m_basename.c_str()); fprintf(fp, "#endif\n"); } + + fprintf(fp, "\t\tif (!unknownOpcode) {\n"); + fprintf(fp, "\t\t\tpos += packetLen;\n"); + fprintf(fp, "\t\t\tptr += packetLen;\n"); + fprintf(fp, "\t\t}\n"); fprintf(fp, "\t} // while\n"); fprintf(fp, "\treturn pos;\n"); fprintf(fp, "}\n"); -- cgit v1.1