diff options
Diffstat (limited to 'emulator/opengl/host/tools/emugen/ApiGen.cpp')
| -rw-r--r-- | emulator/opengl/host/tools/emugen/ApiGen.cpp | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/emulator/opengl/host/tools/emugen/ApiGen.cpp b/emulator/opengl/host/tools/emugen/ApiGen.cpp index 71cd843cd..8be0270db 100644 --- a/emulator/opengl/host/tools/emugen/ApiGen.cpp +++ b/emulator/opengl/host/tools/emugen/ApiGen.cpp @@ -110,7 +110,7 @@ int ApiGen::genFuncTable(const std::string &filename, SideType side) fprintf(fp, "#ifndef __%s_%s_ftable_t_h\n", m_basename.c_str(), sideString(side)); fprintf(fp, "#define __%s_%s_ftable_t_h\n", m_basename.c_str(), sideString(side)); fprintf(fp, "\n\n"); - fprintf(fp, "static struct _%s_funcs_by_name {\n", m_basename.c_str()); + fprintf(fp, "static const struct _%s_funcs_by_name {\n", m_basename.c_str()); fprintf(fp, "\tconst char *name;\n" \ "\tvoid *proc;\n" \ @@ -123,7 +123,7 @@ int ApiGen::genFuncTable(const std::string &filename, SideType side) fprintf(fp, "\t{\"%s\", (void*)%s},\n", e->name().c_str(), e->name().c_str()); } fprintf(fp, "};\n"); - fprintf(fp, "static int %s_num_funcs = sizeof(%s_funcs_by_name) / sizeof(struct _%s_funcs_by_name);\n", + fprintf(fp, "static const int %s_num_funcs = sizeof(%s_funcs_by_name) / sizeof(struct _%s_funcs_by_name);\n", m_basename.c_str(), m_basename.c_str(), m_basename.c_str()); fprintf(fp, "\n\n#endif\n"); return 0; @@ -171,7 +171,7 @@ int ApiGen::genContext(const std::string & filename, SideType side) //client site set error virtual func if (side == CLIENT_SIDE) { - fprintf(fp, "\tvirtual void setError(unsigned int error){};\n"); + fprintf(fp, "\tvirtual void setError(unsigned int error){ (void)error; };\n"); fprintf(fp, "\tvirtual unsigned int getError(){ return 0; };\n"); } @@ -219,7 +219,7 @@ int ApiGen::genEntryPoints(const std::string & filename, SideType side) fprintf(fp, "void %s_%s_context_t::setContextAccessor(CONTEXT_ACCESSOR_TYPE *f) { getCurrentContext = f; }\n", m_basename.c_str(), sideString(side)); - fprintf(fp, "#define GET_CONTEXT %s_%s_context_t * ctx = getCurrentContext() \n", + fprintf(fp, "#define GET_CONTEXT %s_%s_context_t * ctx = getCurrentContext()\n", m_basename.c_str(), sideString(side)); fprintf(fp, "#endif\n\n"); @@ -228,7 +228,7 @@ int ApiGen::genEntryPoints(const std::string & filename, SideType side) EntryPoint *e = &at(i); e->print(fp); fprintf(fp, "{\n"); - fprintf(fp, "\tGET_CONTEXT; \n"); + fprintf(fp, "\tGET_CONTEXT;\n"); bool shouldReturn = !e->retval().isVoid(); bool shouldCallWithContext = (side == CLIENT_SIDE); @@ -239,7 +239,7 @@ int ApiGen::genEntryPoints(const std::string & filename, SideType side) fprintf(fp, "\t%s\n", e->vars()[j].paramCheckExpression().c_str()); } } - fprintf(fp, "\t %sctx->%s(%s", + fprintf(fp, "\t%sctx->%s(%s", shouldReturn ? "return " : "", e->name().c_str(), shouldCallWithContext ? "ctx" : ""); @@ -325,18 +325,10 @@ int ApiGen::genEncoderHeader(const std::string &filename) classname.c_str(), m_basename.c_str(), sideString(CLIENT_SIDE)); fprintf(fp, "\tIOStream *m_stream;\n\n"); - fprintf(fp, "\t%s(IOStream *stream);\n\n", classname.c_str()); - fprintf(fp, "\n};\n\n"); - - fprintf(fp,"extern \"C\" {\n"); + fprintf(fp, "\t%s(IOStream *stream);\n", classname.c_str()); + fprintf(fp, "};\n\n"); - for (size_t i = 0; i < size(); i++) { - fprintf(fp, "\t"); - at(i).print(fp, false, "_enc", /* classname + "::" */"", "void *self"); - fprintf(fp, ";\n"); - } - fprintf(fp, "};\n"); - fprintf(fp, "#endif"); + fprintf(fp, "#endif // GUARD_%s", classname.c_str()); fclose(fp); return 0; @@ -453,15 +445,20 @@ int ApiGen::genEncoderImpl(const std::string &filename) fprintf(fp, "\n\n#include <string.h>\n"); fprintf(fp, "#include \"%s_opcodes.h\"\n\n", m_basename.c_str()); fprintf(fp, "#include \"%s_enc.h\"\n\n\n", m_basename.c_str()); - fprintf(fp, "#include <stdio.h>\n"); - std::string classname = m_basename + "_encoder_context_t"; - size_t n = size(); + fprintf(fp, "#include <stdio.h>\n\n"); + fprintf(fp, "namespace {\n\n"); // unsupport printout fprintf(fp, - "static void enc_unsupported()\n{\n\tALOGE(\"Function is unsupported\\n\");\n}\n\n"); + "void enc_unsupported()\n" + "{\n" + "\tALOGE(\"Function is unsupported\\n\");\n" + "}\n\n"); // entry points; + std::string classname = m_basename + "_encoder_context_t"; + + size_t n = size(); for (size_t i = 0; i < n; i++) { EntryPoint *e = &at(i); @@ -633,19 +630,27 @@ int ApiGen::genEncoderImpl(const std::string &filename) } } //XXX fprintf(fp, "\n\tDBG(\"<<<< %s\\n\");\n", e->name().c_str()); + // todo - return value for pointers if (e->retval().isPointer()) { fprintf(stderr, "WARNING: %s : return value of pointer is unsupported\n", e->name().c_str()); + if (e->flushOnEncode()) { + fprintf(fp, "\tstream->flush();\n"); + } fprintf(fp, "\t return NULL;\n"); } else if (e->retval().type()->name() != "void") { fprintf(fp, "\n\t%s retval;\n", e->retval().type()->name().c_str()); fprintf(fp, "\tstream->readback(&retval, %u);\n",(unsigned) e->retval().type()->bytes()); fprintf(fp, "\treturn retval;\n"); + } else if (e->flushOnEncode()) { + fprintf(fp, "\tstream->flush();\n"); } fprintf(fp, "}\n\n"); } + fprintf(fp, "} // namespace\n\n"); + // constructor fprintf(fp, "%s::%s(IOStream *stream)\n{\n", classname.c_str(), classname.c_str()); fprintf(fp, "\tm_stream = stream;\n\n"); @@ -654,13 +659,13 @@ int ApiGen::genEncoderImpl(const std::string &filename) EntryPoint *e = &at(i); if (e->unsupported()) { fprintf(fp, - "\t%s = (%s_%s_proc_t)(enc_unsupported);\n", + "\tthis->%s = (%s_%s_proc_t) &enc_unsupported;\n", e->name().c_str(), e->name().c_str(), sideString(CLIENT_SIDE)); } else { fprintf(fp, - "\t%s = (%s_enc);\n", + "\tthis->%s = &%s_enc;\n", e->name().c_str(), e->name().c_str()); } @@ -698,7 +703,7 @@ int ApiGen::genDecoderHeader(const std::string &filename) classname.c_str(), m_basename.c_str(), sideString(SERVER_SIDE)); fprintf(fp, "\tsize_t decode(void *buf, size_t bufsize, IOStream *stream);\n"); fprintf(fp, "\n};\n\n"); - fprintf(fp, "#endif\n"); + fprintf(fp, "#endif // GUARD_%s\n", classname.c_str()); fclose(fp); return 0; |
