diff options
author | David 'Digit' Turner <digit@google.com> | 2014-09-25 12:56:12 -0700 |
---|---|---|
committer | bohu <bohu@google.com> | 2014-11-25 12:30:47 -0800 |
commit | d0dc1ddf4a9678714c88aca05883592f04f6c37f (patch) | |
tree | 7b9c64cf17d7f6f41b7ab897fff6df48c7723bed /emulator | |
parent | 7f0f4aab2a307626c13b860179f46017480f7985 (diff) | |
download | sdk-d0dc1ddf4a9678714c88aca05883592f04f6c37f.zip sdk-d0dc1ddf4a9678714c88aca05883592f04f6c37f.tar.gz sdk-d0dc1ddf4a9678714c88aca05883592f04f6c37f.tar.bz2 |
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
Diffstat (limited to 'emulator')
-rw-r--r-- | emulator/opengl/host/tools/emugen/ApiGen.cpp | 17 |
1 files 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"); |