Home | History | Annotate | Download | only in emugen

Lines Matching refs:fp

47 void ApiGen::printHeader(FILE *fp) const
49 fprintf(fp, "// Generated Code - DO NOT EDIT !!\n");
50 fprintf(fp, "// generated by 'emugen'\n");
55 FILE *fp = fopen(filename.c_str(), "wt");
56 if (fp == NULL) {
60 printHeader(fp);
64 fprintf(fp, "#ifndef __%s_%s_proc_t_h\n", basename, sideString(side));
65 fprintf(fp, "#define __%s_%s_proc_t_h\n", basename, sideString(side));
66 fprintf(fp, "\n\n");
67 fprintf(fp, "\n#include \"%s_types.h\"\n",basename);
68 fprintf(fp, "#ifndef %s_APIENTRY\n",basename);
69 fprintf(fp, "#define %s_APIENTRY \n",basename);
70 fprintf(fp, "#endif\n");
76 fprintf(fp, "typedef ");
77 e->retval().printType(fp);
78 fprintf(fp, " (%s_APIENTRY *%s_%s_proc_t) (", basename, e->name().c_str(), sideString(side));
79 if (side == CLIENT_SIDE) { fprintf(fp, "void * ctx"); }
80 if (e->customDecoder() && side == SERVER_SIDE) { fprintf(fp, "void *ctx"); }
87 if (j != 0 || side == CLIENT_SIDE || (side == SERVER_SIDE && e->customDecoder())) fprintf(fp, ", ");
88 evars[j].printType(fp);
91 fprintf(fp, ");\n");
93 fprintf(fp, "\n\n#endif\n");
99 FILE *fp = fopen(filename.c_str(), "wt");
100 if (fp == NULL) {
104 printHeader(fp);
106 fprintf(fp, "#ifndef __%s_%s_ftable_t_h\n", m_basename.c_str(), sideString(side));
107 fprintf(fp, "#define __%s_%s_ftable_t_h\n", m_basename.c_str(), sideString(side));
108 fprintf(fp, "\n\n");
109 fprintf(fp, "static struct _%s_funcs_by_name {\n", m_basename.c_str());
110 fprintf(fp,
119 fprintf(fp, "\t{\"%s\", (void*)%s},\n", e->name().c_str(), e->name().c_str());
121 fprintf(fp, "};\n");
122 fprintf(fp, "static int %s_num_funcs = sizeof(%s_funcs_by_name) / sizeof(struct _%s_funcs_by_name);\n",
124 fprintf(fp, "\n\n#endif\n");
131 FILE *fp = fopen(filename.c_str(), "wt");
132 if (fp == NULL) {
136 printHeader(fp);
138 fprintf(fp, "#ifndef __%s_%s_context_t_h\n", m_basename.c_str(), sideString(side));
139 fprintf(fp, "#define __%s_%s_context_t_h\n", m_basename.c_str(), sideString(side));
141 // fprintf(fp, "\n#include \"%s_types.h\"\n", m_basename.c_str());
142 fprintf(fp, "\n#include \"%s_%s_proc.h\"\n", m_basename.c_str(), sideString(side));
146 fprintf(fp, "#include %s\n", contextHeaders[i].c_str());
148 fprintf(fp, "\n");
150 fprintf(fp, "\nstruct %s_%s_context_t {\n\n", m_basename.c_str(), sideString(side));
153 fprintf(fp, "\t%s_%s_proc_t %s;\n", e->name().c_str(), sideString(side), e->name().c_str());
156 fprintf(fp, "\t//Accessors \n");
162 fprintf(fp, "\tvirtual %s_%s_proc_t set_%s(%s_%s_proc_t f) { %s_%s_proc_t retval = %s; %s = f; return retval;}\n", n, s, n, n, s, n, s, n, n);
166 fprintf(fp, "\t virtual ~%s_%s_context_t() {}\n", m_basename.c_str(), sideString(side));
169 fprintf(fp, "\n\ttypedef %s_%s_context_t *CONTEXT_ACCESSOR_TYPE(void);\n",
171 fprintf(fp, "\tstatic void setContextAccessor(CONTEXT_ACCESSOR_TYPE *f);\n");
175 fprintf(fp, "\tint initDispatchByName( void *(*getProc)(const char *name, void *userData), void *userData);\n");
179 fprintf(fp, "\tvirtual void setError(unsigned int error){};\n");
180 fprintf(fp, "\tvirtual unsigned int getError(){ return 0; };\n");
183 fprintf(fp, "};\n");
185 fprintf(fp, "\n#endif\n");
186 fclose(fp);
199 FILE *fp = fopen(filename.c_str(), "wt");
200 if (fp == NULL) {
205 printHeader(fp);
206 fprintf(fp, "#include <stdio.h>\n");
207 fprintf(fp, "#include <stdlib.h>\n");
208 fprintf(fp, "#include \"%s_%s_context.h\"\n", m_basename.c_str(), sideString(side));
209 fprintf(fp, "\n");
211 fprintf(fp, "#ifndef GL_TRUE\n");
212 fprintf(fp, "extern \"C\" {\n");
215 fprintf(fp, "\t"); at(i).print(fp, false); fprintf(fp, ";\n");
217 fprintf(fp, "};\n\n");
218 fprintf(fp, "#endif\n");
220 fprintf(fp, "#ifndef GET_CONTEXT\n");
221 fprintf(fp, "static %s_%s_context_t::CONTEXT_ACCESSOR_TYPE *getCurrentContext = NULL;\n",
224 fprintf(fp,
227 fprintf(fp, "#define GET_CONTEXT %s_%s_context_t * ctx = getCurrentContext() \n",
229 fprintf(fp, "#endif\n\n");
234 e->print(fp);
235 fprintf(fp, "{\n");
236 fprintf(fp, "\tGET_CONTEXT; \n");
244 fprintf(fp, "\t%s\n", e->vars()[j].paramCheckExpression().c_str());
247 fprintf(fp, "\t %sctx->%s(%s",
255 fprintf(fp, "%s %s",
260 fprintf(fp, ");\n");
261 fprintf(fp, "}\n\n");
263 fclose(fp);
270 FILE *fp = fopen(filename.c_str(), "wt");
271 if (fp == NULL) {
276 printHeader(fp);
277 fprintf(fp, "#ifndef __GUARD_%s_opcodes_h_\n", m_basename.c_str());
278 fprintf(fp, "#define __GUARD_%s_opcodes_h_\n\n", m_basename.c_str());
280 fprintf(fp, "#define OP_%s \t\t\t\t\t%u\n", at(i).name().c_str(), (unsigned int)i + m_baseOpcode);
282 fprintf(fp, "#define OP_last \t\t\t\t\t%u\n", (unsigned int)size() + m_baseOpcode);
283 fprintf(fp,"\n\n#endif\n");
284 fclose(fp);
290 FILE *fp = fopen(filename.c_str(), "wt");
291 if (fp == NULL) {
298 fprintf(fp, "#");
299 at(i).print(fp);
300 fprintf(fp, "%s\n\n", at(i).name().c_str());
303 fclose(fp);
309 FILE *fp = fopen(filename.c_str(), "wt");
310 if (fp == NULL) {
315 printHeader(fp);
318 fprintf(fp, "\n#ifndef GUARD_%s\n", classname.c_str());
319 fprintf(fp, "#define GUARD_%s\n\n", classname.c_str());
321 fprintf(fp, "#include \"IOStream.h\"\n");
322 fprintf(fp, "#include \"%s_%s_context.h\"\n\n\n", m_basename.c_str(), sideString(CLIENT_SIDE));
325 fprintf(fp, "#include %s\n", m_encoderHeaders[i].c_str());
327 fprintf(fp, "\n");
329 fprintf(fp, "struct %s : public %s_%s_context_t {\n\n",
331 fprintf(fp, "\tIOStream *m_stream;\n\n");
333 fprintf(fp, "\t%s(IOStream *stream);\n\n", classname.c_str());
334 fprintf(fp, "\n};\n\n");
336 fprintf(fp,"extern \"C\" {\n");
339 fprintf(fp, "\t");
340 at(i).print(fp, false, "_enc", /* classname + "::" */"", "void *self");
341 fprintf(fp, ";\n");
343 fprintf(fp, "};\n");
344 fprintf(fp, "#endif");
346 fclose(fp);
379 static int writeVarEncodingSize(Var& var, FILE* fp)
383 fprintf(fp, "%u", (unsigned int) var.type()->bytes());
386 fprintf(fp, "__size_%s", var.name().c_str());
393 static void writeVarEncodingExpression(Var& var, FILE* fp)
399 fprintf(fp, "\t*(unsigned int *)(ptr) = __size_%s; ptr += 4;\n", varname);
404 fprintf(fp, "\tif (%s != NULL) ", varname);
406 fprintf(fp, "\t");
410 fprintf(fp, "%s;", var.packExpression().c_str());
412 fprintf(fp, "memcpy(ptr, %s, __size_%s);",
416 fprintf(fp, "ptr += __size_%s;\n", varname);
421 fprintf(fp, "\t\tmemcpy(ptr, &%s, %u); ptr += %u;\n",
430 static void writeVarLargeEncodingExpression(Var& var, FILE* fp)
434 fprintf(fp, "\tstream->writeFully(&__size_%s,4);\n", varname);
436 fprintf(fp, "\tif (%s != NULL) ", varname);
438 fprintf(fp, "\t");
441 fprintf(fp, "%s", var.writeExpression().c_str());
443 fprintf(fp, "stream->writeFully(%s, __size_%s)", varname, varname);
445 fprintf(fp, ";\n");
451 FILE *fp = fopen(filename.c_str(), "wt");
452 if (fp == NULL) {
457 printHeader(fp);
458 fprintf(fp, "\n\n#include <string.h>\n");
459 fprintf(fp, "#include \"%s_opcodes.h\"\n\n", m_basename.c_str());
460 fprintf(fp, "#include \"%s_enc.h\"\n\n\n", m_basename.c_str());
461 fprintf(fp, "#include <stdio.h>\n");
466 fprintf(fp,
476 e->print(fp, true, "_enc", /* classname + "::" */"", "void *self");
477 fprintf(fp, "{\n");
479 // fprintf(fp, "\n\tDBG(\">>>> %s\\n\");\n", e->name().c_str());
480 fprintf(fp, "\n\t%s *ctx = (%s *)self;\n",
483 fprintf(fp, "\tIOStream *stream = ctx->m_stream;\n\n");
499 fprintf(fp, "\tconst unsigned int __size_%s = ", varname);
502 fprintf(fp, "%s;\n", buff);
516 fprintf(fp, "\t unsigned char *ptr;\n");
517 fprintf(fp, "\t const size_t packetSize = 8");
520 fprintf(fp, " + ");
521 npointers += writeVarEncodingSize(evars[j], fp);
524 fprintf(fp, " + %zu*4", npointers);
526 fprintf(fp, ";\n");
549 fprintf(fp, "\tptr = stream->alloc(packetSize);\n");
553 fprintf(fp, "\tptr = stream->alloc(");
557 fprintf(fp,"8"); plus = " + ";
562 fprintf(fp, "%s", plus); plus = " + ";
563 npointers += writeVarEncodingSize(evars[j], fp);
566 fprintf(fp, "%s%zu*4", plus, npointers); plus = " + ";
569 fprintf(fp,");\n");
574 fprintf(fp, "\tint tmp = OP_%s;memcpy(ptr, &tmp, 4); ptr += 4;\n", e->name().c_str());
575 fprintf(fp, "\tmemcpy(ptr, &packetSize, 4); ptr += 4;\n\n");
583 writeVarEncodingExpression(evars[j],fp);
588 fprintf(fp, "\tstream->flush();\n");
595 writeVarLargeEncodingExpression(evars[j], fp);
604 fprintf(fp, "\t const size_t packetSize = 8");
607 fprintf(fp, " + %s", buff);
609 fprintf(fp, " + %u * 4;\n", (unsigned int) npointers);
612 fprintf(fp, "\t unsigned char *ptr = stream->alloc(packetSize);\n\n");
615 fprintf(fp, "\tint tmp = OP_%s; memcpy(ptr, &tmp, 4); ptr += 4;\n", e->name().c_str());
616 fprintf(fp, "\tmemcpy(ptr, &packetSize, 4); ptr += 4;\n\n");
620 writeVarEncodingExpression(evars[j], fp);
631 fprintf(fp, "\tif (%s != NULL) ",varname);
633 fprintf(fp, "\t");
635 fprintf(fp, "stream->readback(%s, __size_%s);\n",
640 //XXX fprintf(fp, "\n\tDBG(\"<<<< %s\\n\");\n", e->name().c_str());
645 fprintf(fp, "\t return NULL;\n");
647 fprintf(fp, "\n\t%s retval;\n", e->retval().type()->name().c_str());
648 fprintf(fp, "\tstream->readback(&retval, %u);\n",(uint) e->retval().type()->bytes());
649 fprintf(fp, "\treturn retval;\n");
651 fprintf(fp, "}\n\n");
655 fprintf(fp, "%s::%s(IOStream *stream)\n{\n", classname.c_str(), classname.c_str());
656 fprintf(fp, "\tm_stream = stream;\n\n");
661 fprintf(fp, "\tset_%s((%s_%s_proc_t)(enc_unsupported));\n", e->name().c_str(), e->name().c_str(), sideString(CLIENT_SIDE));
663 fprintf(fp, "\tset_%s(%s_enc);\n", e->name().c_str(), e->name().c_str());
667 fprintf(fp, "\tmemcpy((void *)(&%s), (const void *)(&enc_unsupported), sizeof(%s));\n",
671 fprintf(fp, "\t%s = %s_enc;\n", e->name().c_str(), e->name().c_str());
675 fprintf(fp, "}\n\n");
677 fclose(fp);
684 FILE *fp = fopen(filename.c_str(), "wt");
685 if (fp == NULL) {
690 printHeader(fp);
693 fprintf(fp, "\n#ifndef GUARD_%s\n", classname.c_str());
694 fprintf(fp, "#define GUARD_%s\n\n", classname.c_str());
696 fprintf(fp, "#include \"IOStream.h\" \n");
697 fprintf(fp, "#include \"%s_%s_context.h\"\n\n\n", m_basename.c_str(), sideString(SERVER_SIDE));
700 fprintf(fp, "#include %s\n", m_decoderHeaders[i].c_str());
702 fprintf(fp, "\n");
704 fprintf(fp, "struct %s : public %s_%s_context_t {\n\n",
706 fprintf(fp, "\tsize_t decode(void *buf, size_t bufsize, IOStream *stream);\n");
707 fprintf(fp, "\n};\n\n");
708 fprintf(fp, "#endif\n");
710 fclose(fp);
716 FILE *fp = fopen(filename.c_str(), "wt");
717 if (fp == NULL) {
721 printHeader(fp);
725 fprintf(fp, "\n\n#include <string.h>\n");
726 fprintf(fp, "#include \"%s_%s_context.h\"\n\n\n", m_basename.c_str(), sideString(side));
727 fprintf(fp, "#include <stdio.h>\n\n");
730 fprintf(fp, "int %s::initDispatchByName(void *(*getProc)(const char *, void *userData), void *userData)\n{\n", classname.c_str());
731 fprintf(fp, "\tvoid *ptr;\n\n");
734 fprintf(fp, "\tptr = getProc(\"%s\", userData); set_%s((%s_%s_proc_t)ptr);\n",
741 fprintf(fp, "\treturn 0;\n");
742 fprintf(fp, "}\n\n");
743 fclose(fp);
749 FILE *fp = fopen(filename.c_str(), "wt");
750 if (fp == NULL) {
755 printHeader(fp);
761 fprintf(fp, "\n\n#include <string.h>\n");
762 fprintf(fp, "#include \"%s_opcodes.h\"\n\n", m_basename.c_str());
763 fprintf(fp, "#include \"%s_dec.h\"\n\n\n", m_basename.c_str());
764 fprintf(fp, "#include <stdio.h>\n\n");
765 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");
768 fprintf(fp, "size_t %s::decode(void *buf, size_t len, IOStream *stream)\n{\n", classname.c_str());
769 fprintf(fp,
799 fprintf(fp, "\t\t\tcase OP_%s:\n", e->name().c_str());
800 fprintf(fp, "\t\t\t{\n");
814 fprintf(fp, "\t\t\t*(%s *)(&tmpBuf[%s]) = ", retvalType.c_str(),
820 fprintf(fp, "\t\t\tthis->%s(", e->name().c_str());
822 fprintf(fp, "this"); // add a context to the call
825 fprintf(fp, "#ifdef DEBUG_PRINTOUT\n");
826 fprintf(fp, "\t\t\tfprintf(stderr,\"%s: %s(%s)\\n\"", m_basename.c_str(), e->name().c_str(), printString.c_str());
827 if (e->vars().size() > 0 && !e->vars()[0].isVoid()) fprintf(fp, ",");
836 if ((pass == PASS_FunctionCall) && (j != 0 || e->customDecoder())) fprintf(fp, ", ");
837 if (pass == PASS_DebugPrint && j != 0) fprintf(fp, ", ");
841 fprintf(fp, "*(%s *)(ptr + %s)", v->type()->name().c_str(), varoffset.c_str());
847 fprintf(fp, "\t\t\tsize_t tmpPtr%uSize = (size_t)*(unsigned int *)(ptr + %s);\n",
849 fprintf(fp, "unsigned char *tmpPtr%u = (ptr + %s + 4);\n",
854 fprintf(fp, "*((unsigned int *)(ptr + %s)) == 0 ? NULL : (%s)(ptr + %s + 4)",
857 fprintf(fp, "(%s)(ptr + %s + 4)",
861 fprintf(fp, "(%s)(ptr + %s + 4), *(unsigned int *)(ptr + %s)",
868 fprintf(fp, "\t\t\tsize_t tmpPtr%uSize = (size_t)*(unsigned int *)(ptr + %s);\n",
871 fprintf(fp, "\t\t\tsize_t totalTmpSize = tmpPtr%uSize;\n", (uint)j);
873 fprintf(fp, "\t\t\ttotalTmpSize += tmpPtr%uSize;\n", (uint)j);
881 fprintf(fp, "\t\t\tunsigned char *tmpPtr%u = &tmpBuf[%s];\n",
885 fprintf(fp, "tmpPtr%uSize == 0 ? NULL : (%s)(tmpPtr%u)",
888 fprintf(fp, "(%s)(tmpPtr%u)", v->type()->name().c_str(), (uint) j);
891 fprintf(fp, "(%s)(tmpPtr%u), *(unsigned int *)(ptr + %s)",
901 if (pass == PASS_FunctionCall || pass == PASS_DebugPrint) fprintf(fp, ");\n");
902 if (pass == PASS_DebugPrint) fprintf(fp, "#endif\n");
907 fprintf(fp, "\t\t\tsize_t totalTmpSize = sizeof(%s);\n", retvalType.c_str());
909 fprintf(fp, "\t\t\ttotalTmpSize += sizeof(%s);\n", retvalType.c_str());
914 fprintf(fp, "\t\t\tunsigned char *tmpBuf = stream->alloc(totalTmpSize);\n");
921 fprintf(fp, "\t\t\tstream->flush();\n");
924 fprintf(fp, "\t\t\tpos += *(int *)(ptr + 4);\n");
925 fprintf(fp, "\t\t\tptr += *(int *)(ptr + 4);\n");
929 fprintf(fp, "\t\t\t}\n");
930 fprintf(fp, "#ifdef CHECK_GL_ERROR\n");
931 fprintf(fp, "\t\t\tsprintf(lastCall, \"%s\");\n", e->name().c_str());
932 fprintf(fp, "#endif\n");
933 fprintf(fp, "\t\t\tbreak;\n");
937 fprintf(fp, "\t\t\tdefault:\n");
938 fprintf(fp, "\t\t\t\tunknownOpcode = true;\n");
939 fprintf(fp, "\t\t} //switch\n");
941 fprintf(fp, "#ifdef CHECK_GL_ERROR\n");
942 fprintf(fp, "\tint err = this->glGetError();\n");
943 fprintf(fp, "\tif (err) fprintf(stderr, \"%s Error: 0x%%X in %%s\\n\", err, lastCall);\n", m_basename.c_str());
944 fprintf(fp, "#endif\n");
946 fprintf(fp, "\t} // while\n");
947 fprintf(fp, "\treturn pos;\n");
948 fprintf(fp, "}\n");
950 fclose(fp);
979 FILE *fp = fopen(attribFilename.c_str(), "rt");
980 if (fp == NULL) {
990 while (fgets(buf, sizeof(buf), fp) != NULL) {