rsg_generator.c revision bda75a977726835d74b2380d7e92360ed2a1ff7a
1 2#include "spec.h" 3#include <stdio.h> 4 5void printFileHeader(FILE *f) { 6 fprintf(f, "/*\n"); 7 fprintf(f, " * Copyright (C) 2011 The Android Open Source Project\n"); 8 fprintf(f, " *\n"); 9 fprintf(f, " * Licensed under the Apache License, Version 2.0 (the \"License\");\n"); 10 fprintf(f, " * you may not use this file except in compliance with the License.\n"); 11 fprintf(f, " * You may obtain a copy of the License at\n"); 12 fprintf(f, " *\n"); 13 fprintf(f, " * http://www.apache.org/licenses/LICENSE-2.0\n"); 14 fprintf(f, " *\n"); 15 fprintf(f, " * Unless required by applicable law or agreed to in writing, software\n"); 16 fprintf(f, " * distributed under the License is distributed on an \"AS IS\" BASIS,\n"); 17 fprintf(f, " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"); 18 fprintf(f, " * See the License for the specific language governing permissions and\n"); 19 fprintf(f, " * limitations under the License.\n"); 20 fprintf(f, " */\n\n"); 21} 22 23void printVarType(FILE *f, const VarType *vt) { 24 int ct; 25 if (vt->isConst) { 26 fprintf(f, "const "); 27 } 28 29 switch (vt->type) { 30 case 0: 31 fprintf(f, "void"); 32 break; 33 case 1: 34 fprintf(f, "int%i_t", vt->bits); 35 break; 36 case 2: 37 fprintf(f, "uint%i_t", vt->bits); 38 break; 39 case 3: 40 if (vt->bits == 32) 41 fprintf(f, "float"); 42 else 43 fprintf(f, "double"); 44 break; 45 case 4: 46 fprintf(f, "%s", vt->typeName); 47 break; 48 } 49 50 if (vt->ptrLevel) { 51 fprintf(f, " "); 52 for (ct=0; ct < vt->ptrLevel; ct++) { 53 fprintf(f, "*"); 54 } 55 } 56} 57 58void printVarTypeAndName(FILE *f, const VarType *vt) { 59 printVarType(f, vt); 60 61 if (vt->name[0]) { 62 fprintf(f, " %s", vt->name); 63 } 64} 65 66void printArgList(FILE *f, const ApiEntry * api, int assumePrevious) { 67 int ct; 68 for (ct=0; ct < api->paramCount; ct++) { 69 if (ct || assumePrevious) { 70 fprintf(f, ", "); 71 } 72 printVarTypeAndName(f, &api->params[ct]); 73 } 74} 75 76void printStructures(FILE *f) { 77 int ct; 78 int ct2; 79 80 for (ct=0; ct < apiCount; ct++) { 81 fprintf(f, "typedef struct RS_CMD_%s_rec RS_CMD_%s;\n", apis[ct].name, apis[ct].name); 82 } 83 fprintf(f, "\n"); 84 85 for (ct=0; ct < apiCount; ct++) { 86 const ApiEntry * api = &apis[ct]; 87 fprintf(f, "#define RS_CMD_ID_%s %i\n", api->name, ct+1); 88 fprintf(f, "struct RS_CMD_%s_rec {\n", api->name); 89 //fprintf(f, " RsCommandHeader _hdr;\n"); 90 91 for (ct2=0; ct2 < api->paramCount; ct2++) { 92 fprintf(f, " "); 93 printVarTypeAndName(f, &api->params[ct2]); 94 fprintf(f, ";\n"); 95 } 96 fprintf(f, "};\n\n"); 97 } 98} 99 100void printFuncDecl(FILE *f, const ApiEntry *api, const char *prefix, int addContext, int isFnPtr) { 101 printVarTypeAndName(f, &api->ret); 102 if (isFnPtr) { 103 char t[1024]; 104 strcpy(t, api->name); 105 if (strlen(prefix) == 0) { 106 if (t[0] > 'A' && t[0] < 'Z') { 107 t[0] -= 'A' - 'a'; 108 } 109 } 110 fprintf(f, " (* %s%s) (", prefix, api->name); 111 } else { 112 fprintf(f, " %s%s (", prefix, api->name); 113 } 114 if (!api->nocontext) { 115 if (addContext) { 116 fprintf(f, "Context *"); 117 } else { 118 fprintf(f, "RsContext rsc"); 119 } 120 } 121 printArgList(f, api, !api->nocontext); 122 fprintf(f, ")"); 123} 124 125void printFuncDecls(FILE *f, const char *prefix, int addContext) { 126 int ct; 127 for (ct=0; ct < apiCount; ct++) { 128 printFuncDecl(f, &apis[ct], prefix, addContext, 0); 129 fprintf(f, ";\n"); 130 } 131 fprintf(f, "\n\n"); 132} 133 134void printFuncPointers(FILE *f, int addContext) { 135 fprintf(f, "\n"); 136 fprintf(f, "typedef struct RsApiEntrypoints {\n"); 137 int ct; 138 for (ct=0; ct < apiCount; ct++) { 139 fprintf(f, " "); 140 printFuncDecl(f, &apis[ct], "", addContext, 1); 141 fprintf(f, ";\n"); 142 } 143 fprintf(f, "} RsApiEntrypoints_t;\n\n"); 144} 145 146void printPlaybackFuncs(FILE *f, const char *prefix) { 147 int ct; 148 for (ct=0; ct < apiCount; ct++) { 149 if (apis[ct].direct) { 150 continue; 151 } 152 153 fprintf(f, "void %s%s (Context *, const void *);\n", prefix, apis[ct].name); 154 } 155} 156 157static int hasInlineDataPointers(const ApiEntry * api) { 158 int ret = 0; 159 int ct; 160 if (api->sync || api->ret.typeName[0]) { 161 return 0; 162 } 163 for (ct=0; ct < api->paramCount; ct++) { 164 const VarType *vt = &api->params[ct]; 165 166 if (!vt->isConst && vt->ptrLevel) { 167 // Non-const pointers cannot be inlined. 168 return 0; 169 } 170 if (vt->ptrLevel > 1) { 171 // not handled yet. 172 return 0; 173 } 174 175 if (vt->isConst && vt->ptrLevel) { 176 // Non-const pointers cannot be inlined. 177 ret = 1; 178 } 179 } 180 return ret; 181} 182 183void printApiCpp(FILE *f) { 184 int ct; 185 int ct2; 186 187 fprintf(f, "#include \"rsDevice.h\"\n"); 188 fprintf(f, "#include \"rsContext.h\"\n"); 189 fprintf(f, "#include \"rsThreadIO.h\"\n"); 190 //fprintf(f, "#include \"rsgApiStructs.h\"\n"); 191 fprintf(f, "#include \"rsgApiFuncDecl.h\"\n"); 192 fprintf(f, "#include \"rsFifo.h\"\n"); 193 fprintf(f, "\n"); 194 fprintf(f, "using namespace android;\n"); 195 fprintf(f, "using namespace android::renderscript;\n"); 196 fprintf(f, "\n"); 197 198 printFuncPointers(f, 0); 199 200 // Generate RS funcs for local fifo 201 for (ct=0; ct < apiCount; ct++) { 202 int needFlush = 0; 203 const ApiEntry * api = &apis[ct]; 204 205 fprintf(f, "static "); 206 printFuncDecl(f, api, "LF_", 0, 0); 207 fprintf(f, "\n{\n"); 208 if (api->direct) { 209 fprintf(f, " "); 210 if (api->ret.typeName[0]) { 211 fprintf(f, "return "); 212 } 213 fprintf(f, "rsi_%s(", api->name); 214 if (!api->nocontext) { 215 fprintf(f, "(Context *)rsc"); 216 } 217 for (ct2=0; ct2 < api->paramCount; ct2++) { 218 const VarType *vt = &api->params[ct2]; 219 if (ct2 > 0 || !api->nocontext) { 220 fprintf(f, ", "); 221 } 222 fprintf(f, "%s", vt->name); 223 } 224 fprintf(f, ");\n"); 225 } else { 226 fprintf(f, " ThreadIO *io = &((Context *)rsc)->mIO;\n"); 227 fprintf(f, " const uint32_t size = sizeof(RS_CMD_%s);\n", api->name); 228 if (hasInlineDataPointers(api)) { 229 fprintf(f, " uint32_t dataSize = 0;\n"); 230 for (ct2=0; ct2 < api->paramCount; ct2++) { 231 const VarType *vt = &api->params[ct2]; 232 if (vt->isConst && vt->ptrLevel) { 233 fprintf(f, " dataSize += %s_length;\n", vt->name); 234 } 235 } 236 } 237 238 //fprintf(f, " ALOGE(\"add command %s\\n\");\n", api->name); 239 if (hasInlineDataPointers(api)) { 240 fprintf(f, " RS_CMD_%s *cmd = NULL;\n", api->name); 241 fprintf(f, " if (dataSize < io->getMaxInlineSize()) {;\n"); 242 fprintf(f, " cmd = static_cast<RS_CMD_%s *>(io->coreHeader(RS_CMD_ID_%s, dataSize + size));\n", api->name, api->name); 243 fprintf(f, " } else {\n"); 244 fprintf(f, " cmd = static_cast<RS_CMD_%s *>(io->coreHeader(RS_CMD_ID_%s, size));\n", api->name, api->name); 245 fprintf(f, " }\n"); 246 fprintf(f, " uint8_t *payload = (uint8_t *)&cmd[1];\n"); 247 } else { 248 fprintf(f, " RS_CMD_%s *cmd = static_cast<RS_CMD_%s *>(io->coreHeader(RS_CMD_ID_%s, size));\n", api->name, api->name, api->name); 249 } 250 251 for (ct2=0; ct2 < api->paramCount; ct2++) { 252 const VarType *vt = &api->params[ct2]; 253 needFlush += vt->ptrLevel; 254 if (vt->ptrLevel && hasInlineDataPointers(api)) { 255 fprintf(f, " if (dataSize < io->getMaxInlineSize()) {\n"); 256 fprintf(f, " memcpy(payload, %s, %s_length);\n", vt->name, vt->name); 257 fprintf(f, " cmd->%s = (", vt->name); 258 printVarType(f, vt); 259 fprintf(f, ")(payload - ((uint8_t *)&cmd[1]));\n"); 260 fprintf(f, " payload += %s_length;\n", vt->name); 261 fprintf(f, " } else {\n"); 262 fprintf(f, " cmd->%s = %s;\n", vt->name, vt->name); 263 fprintf(f, " }\n"); 264 265 } else { 266 fprintf(f, " cmd->%s = %s;\n", vt->name, vt->name); 267 } 268 } 269 if (api->ret.typeName[0] || api->sync) { 270 needFlush = 1; 271 } 272 273 fprintf(f, " io->coreCommit();\n"); 274 if (hasInlineDataPointers(api)) { 275 fprintf(f, " if (dataSize >= io->getMaxInlineSize()) {\n"); 276 fprintf(f, " io->coreGetReturn(NULL, 0);\n"); 277 fprintf(f, " }\n"); 278 } else if (api->ret.typeName[0]) { 279 fprintf(f, "\n "); 280 printVarType(f, &api->ret); 281 fprintf(f, " ret;\n"); 282 fprintf(f, " io->coreGetReturn(&ret, sizeof(ret));\n"); 283 fprintf(f, " return ret;\n"); 284 } else if (needFlush) { 285 fprintf(f, " io->coreGetReturn(NULL, 0);\n"); 286 } 287 } 288 fprintf(f, "};\n\n"); 289 290 291 // Generate a remote sender function 292 const char * str = "core"; 293 if (api->direct) { 294 str = "async"; 295 } 296 297 fprintf(f, "static "); 298 printFuncDecl(f, api, "RF_", 0, 0); 299 fprintf(f, "\n{\n"); 300 fprintf(f, " ThreadIO *io = &((Context *)rsc)->mIO;\n"); 301 fprintf(f, " const uint32_t cmdID = RS_CMD_ID_%s;\n", api->name); 302 fprintf(f, " io->%sWrite(&cmdID, sizeof(cmdID));\n\n", str); 303 304 for (ct2=0; ct2 < api->paramCount; ct2++) { 305 const VarType *vt = &api->params[ct2]; 306 if (vt->ptrLevel == 0) { 307 fprintf(f, " io->%sWrite(& %s, sizeof(%s));\n", str, vt->name, vt->name); 308 } 309 } 310 fprintf(f, "\n"); 311 312 for (ct2=0; ct2 < api->paramCount; ct2++) { 313 const VarType *vt = &api->params[ct2]; 314 if ((vt->ptrLevel == 1) && (vt->isConst)) { 315 fprintf(f, " io->%sWrite(%s, %s_length);\n", str, vt->name, vt->name); 316 } 317 } 318 fprintf(f, "\n"); 319 320 for (ct2=0; ct2 < api->paramCount; ct2++) { 321 const VarType *vt = &api->params[ct2]; 322 if ((vt->ptrLevel == 2) && (vt->isConst)) { 323 fprintf(f, " for (size_t ct = 0; ct < (%s_length_length / sizeof(%s_length)); ct++) {\n", vt->name, vt->name); 324 fprintf(f, " io->%sWrite(%s[ct], %s_length[ct]);\n", str, vt->name, vt->name); 325 fprintf(f, " }\n"); 326 } 327 } 328 fprintf(f, "\n"); 329 330 for (ct2=0; ct2 < api->paramCount; ct2++) { 331 const VarType *vt = &api->params[ct2]; 332 if ((vt->ptrLevel == 1) && (!vt->isConst)) { 333 fprintf(f, " io->%sGetReturn(%s, %s_length);\n", str, vt->name, vt->name); 334 } 335 } 336 fprintf(f, "\n"); 337 338 for (ct2=0; ct2 < api->paramCount; ct2++) { 339 const VarType *vt = &api->params[ct2]; 340 if ((vt->ptrLevel == 2) && (!vt->isConst)) { 341 fprintf(f, " for (size_t ct = 0; ct < (%s_length_length / sizeof(%s_length)); ct++) {\n", vt->name, vt->name); 342 fprintf(f, " io->%sGetReturn(%s[ct], %s_length[ct]);\n", str, vt->name, vt->name); 343 fprintf(f, " }\n"); 344 } 345 } 346 fprintf(f, "\n"); 347 348 if (api->ret.typeName[0]) { 349 fprintf(f, " "); 350 printVarType(f, &api->ret); 351 fprintf(f, " retValue;\n"); 352 fprintf(f, " io->%sGetReturn(&retValue, sizeof(retValue));\n", str); 353 fprintf(f, " return retValue;\n"); 354 } else /*if (api->sync)*/ { 355 fprintf(f, " io->%sGetReturn(NULL, 0);\n", str); 356 } 357 fprintf(f, "}\n\n"); 358 } 359 360 fprintf(f, "\n"); 361 fprintf(f, "static RsApiEntrypoints_t s_LocalTable = {\n"); 362 for (ct=0; ct < apiCount; ct++) { 363 fprintf(f, " LF_%s,\n", apis[ct].name); 364 } 365 fprintf(f, "};\n"); 366 367 fprintf(f, "\n"); 368 fprintf(f, "static RsApiEntrypoints_t s_RemoteTable = {\n"); 369 for (ct=0; ct < apiCount; ct++) { 370 fprintf(f, " RF_%s,\n", apis[ct].name); 371 } 372 fprintf(f, "};\n"); 373 374 fprintf(f, "static RsApiEntrypoints_t *s_CurrentTable = &s_LocalTable;\n\n"); 375 for (ct=0; ct < apiCount; ct++) { 376 int needFlush = 0; 377 const ApiEntry * api = &apis[ct]; 378 379 printFuncDecl(f, api, "rs", 0, 0); 380 fprintf(f, "\n{\n"); 381 fprintf(f, " "); 382 if (api->ret.typeName[0]) { 383 fprintf(f, "return "); 384 } 385 fprintf(f, "s_CurrentTable->%s(", api->name); 386 387 if (!api->nocontext) { 388 fprintf(f, "(Context *)rsc"); 389 } 390 391 for (ct2=0; ct2 < api->paramCount; ct2++) { 392 const VarType *vt = &api->params[ct2]; 393 if (ct2 > 0 || !api->nocontext) { 394 fprintf(f, ", "); 395 } 396 fprintf(f, "%s", vt->name); 397 } 398 fprintf(f, ");\n"); 399 fprintf(f, "}\n\n"); 400 } 401 402} 403 404void printPlaybackCpp(FILE *f) { 405 int ct; 406 int ct2; 407 408 fprintf(f, "#include \"rsDevice.h\"\n"); 409 fprintf(f, "#include \"rsContext.h\"\n"); 410 fprintf(f, "#include \"rsThreadIO.h\"\n"); 411 fprintf(f, "#include \"rsgApiFuncDecl.h\"\n"); 412 fprintf(f, "\n"); 413 fprintf(f, "namespace android {\n"); 414 fprintf(f, "namespace renderscript {\n"); 415 fprintf(f, "\n"); 416 417 for (ct=0; ct < apiCount; ct++) { 418 const ApiEntry * api = &apis[ct]; 419 int needFlush = 0; 420 421 if (api->direct) { 422 continue; 423 } 424 425 fprintf(f, "void rsp_%s(Context *con, const void *vp, size_t cmdSizeBytes) {\n", api->name); 426 fprintf(f, " const RS_CMD_%s *cmd = static_cast<const RS_CMD_%s *>(vp);\n", api->name, api->name); 427 428 if (hasInlineDataPointers(api)) { 429 fprintf(f, " const uint8_t *baseData = 0;\n"); 430 fprintf(f, " if (cmdSizeBytes != sizeof(RS_CMD_%s)) {\n", api->name); 431 fprintf(f, " baseData = &((const uint8_t *)vp)[sizeof(*cmd)];\n"); 432 fprintf(f, " }\n"); 433 } 434 435 fprintf(f, " "); 436 if (api->ret.typeName[0]) { 437 fprintf(f, "\n "); 438 printVarType(f, &api->ret); 439 fprintf(f, " ret = "); 440 } 441 fprintf(f, "rsi_%s(con", api->name); 442 for (ct2=0; ct2 < api->paramCount; ct2++) { 443 const VarType *vt = &api->params[ct2]; 444 needFlush += vt->ptrLevel; 445 446 if (hasInlineDataPointers(api) && vt->ptrLevel) { 447 fprintf(f, ",\n (const %s *)&baseData[(intptr_t)cmd->%s]", vt->typeName, vt->name); 448 } else { 449 fprintf(f, ",\n cmd->%s", vt->name); 450 } 451 } 452 fprintf(f, ");\n"); 453 454 if (hasInlineDataPointers(api)) { 455 fprintf(f, " size_t totalSize = 0;\n"); 456 for (ct2=0; ct2 < api->paramCount; ct2++) { 457 if (api->params[ct2].ptrLevel) { 458 fprintf(f, " totalSize += cmd->%s_length;\n", api->params[ct2].name); 459 } 460 } 461 462 fprintf(f, " if ((totalSize != 0) && (cmdSizeBytes == sizeof(RS_CMD_%s))) {\n", api->name); 463 fprintf(f, " con->mIO.coreSetReturn(NULL, 0);\n"); 464 fprintf(f, " }\n"); 465 } else if (api->ret.typeName[0]) { 466 fprintf(f, " con->mIO.coreSetReturn(&ret, sizeof(ret));\n"); 467 } else if (api->sync || needFlush) { 468 fprintf(f, " con->mIO.coreSetReturn(NULL, 0);\n"); 469 } 470 471 fprintf(f, "};\n\n"); 472 } 473 474 for (ct=0; ct < apiCount; ct++) { 475 const ApiEntry * api = &apis[ct]; 476 int needFlush = 0; 477 478 fprintf(f, "void rspr_%s(Context *con, ThreadIO *io) {\n", api->name); 479 fprintf(f, " RS_CMD_%s cmd;\n", api->name); 480 481 for (ct2=0; ct2 < api->paramCount; ct2++) { 482 const VarType *vt = &api->params[ct2]; 483 if (vt->ptrLevel == 0) { 484 fprintf(f, " io->coreRead(&cmd.%s, sizeof(cmd.%s));\n", vt->name, vt->name); 485 } 486 } 487 fprintf(f, "\n"); 488 489 for (ct2=0; ct2 < api->paramCount; ct2++) { 490 const VarType *vt = &api->params[ct2]; 491 if (vt->ptrLevel == 1) { 492 fprintf(f, " cmd.%s = (", vt->name); 493 printVarType(f, vt); 494 fprintf(f, ")malloc(cmd.%s_length);\n", vt->name); 495 496 if (vt->isConst) { 497 fprintf(f, " if (cmd.%s_length) io->coreRead((void *)cmd.%s, cmd.%s_length);\n", vt->name, vt->name, vt->name); 498 } 499 } 500 } 501 fprintf(f, "\n"); 502 503 for (ct2=0; ct2 < api->paramCount; ct2++) { 504 const VarType *vt = &api->params[ct2]; 505 if (vt->ptrLevel == 2) { 506 fprintf(f, " for (size_t ct = 0; ct < (cmd.%s_length_length / sizeof(cmd.%s_length)); ct++) {\n", vt->name, vt->name); 507 fprintf(f, " cmd.%s = (", vt->name); 508 printVarType(f, vt); 509 fprintf(f, ")malloc(cmd.%s_length[ct]);\n", vt->name); 510 fprintf(f, " io->coreRead(& cmd.%s, cmd.%s_length[ct]);\n", vt->name, vt->name); 511 fprintf(f, " }\n"); 512 } 513 } 514 fprintf(f, "\n"); 515 516 if (api->ret.typeName[0]) { 517 fprintf(f, " "); 518 printVarType(f, &api->ret); 519 fprintf(f, " ret =\n"); 520 } 521 522 fprintf(f, " rsi_%s(", api->name); 523 if (!api->nocontext) { 524 fprintf(f, "con"); 525 } 526 for (ct2=0; ct2 < api->paramCount; ct2++) { 527 const VarType *vt = &api->params[ct2]; 528 if (ct2 > 0 || !api->nocontext) { 529 fprintf(f, ",\n"); 530 } 531 fprintf(f, " cmd.%s", vt->name); 532 } 533 fprintf(f, ");\n"); 534 535 for (ct2=0; ct2 < api->paramCount; ct2++) { 536 const VarType *vt = &api->params[ct2]; 537 if ((vt->ptrLevel == 1) && (!vt->isConst)) { 538 fprintf(f, " io->coreSetReturn((void *)cmd.%s, cmd.%s_length);\n", vt->name, vt->name); 539 } 540 } 541 542 for (ct2=0; ct2 < api->paramCount; ct2++) { 543 const VarType *vt = &api->params[ct2]; 544 if ((vt->ptrLevel == 2) && (!vt->isConst)) { 545 fprintf(f, " for (size_t ct = 0; ct < (cmd.%s_length_length / sizeof(cmd.%s_length)); ct++) {\n", vt->name, vt->name); 546 fprintf(f, " io->coreSetReturn((void *)cmd.%s[ct], cmd.%s_length[ct]);\n", vt->name, vt->name); 547 fprintf(f, " }\n"); 548 } 549 } 550 fprintf(f, "\n"); 551 552 if (api->ret.typeName[0]) { 553 fprintf(f, " io->coreSetReturn(&ret, sizeof(ret));\n"); 554 } else /*if (needFlush)*/ { 555 fprintf(f, " io->coreSetReturn(NULL, 0);\n"); 556 } 557 558 for (ct2=0; ct2 < api->paramCount; ct2++) { 559 const VarType *vt = &api->params[ct2]; 560 if (vt->ptrLevel == 1) { 561 fprintf(f, " free((void *)cmd.%s);\n", vt->name); 562 } 563 } 564 for (ct2=0; ct2 < api->paramCount; ct2++) { 565 const VarType *vt = &api->params[ct2]; 566 if (vt->ptrLevel == 2) { 567 fprintf(f, " for (size_t ct = 0; ct < (cmd.%s_length_length / sizeof(cmd.%s_length)); ct++) {\n", vt->name, vt->name); 568 fprintf(f, " free((void *)cmd.%s);\n", vt->name); 569 fprintf(f, " }\n"); 570 } 571 } 572 573 fprintf(f, "};\n\n"); 574 } 575 576 fprintf(f, "RsPlaybackLocalFunc gPlaybackFuncs[%i] = {\n", apiCount + 1); 577 fprintf(f, " NULL,\n"); 578 for (ct=0; ct < apiCount; ct++) { 579 if (apis[ct].direct) { 580 fprintf(f, " NULL,\n"); 581 } else { 582 fprintf(f, " %s%s,\n", "rsp_", apis[ct].name); 583 } 584 } 585 fprintf(f, "};\n"); 586 587 fprintf(f, "RsPlaybackRemoteFunc gPlaybackRemoteFuncs[%i] = {\n", apiCount + 1); 588 fprintf(f, " NULL,\n"); 589 for (ct=0; ct < apiCount; ct++) { 590 fprintf(f, " %s%s,\n", "rspr_", apis[ct].name); 591 } 592 fprintf(f, "};\n"); 593 594 fprintf(f, "};\n"); 595 fprintf(f, "};\n"); 596} 597 598void yylex(); 599 600int main(int argc, char **argv) { 601 if (argc != 3) { 602 fprintf(stderr, "usage: %s commandFile outFile\n", argv[0]); 603 return 1; 604 } 605 const char* rsgFile = argv[1]; 606 const char* outFile = argv[2]; 607 FILE* input = fopen(rsgFile, "r"); 608 609 char choice = fgetc(input); 610 fclose(input); 611 612 if (choice < '0' || choice > '3') { 613 fprintf(stderr, "Uknown command: \'%c\'\n", choice); 614 return -2; 615 } 616 617 yylex(); 618 // printf("# of lines = %d\n", num_lines); 619 620 FILE *f = fopen(outFile, "w"); 621 622 printFileHeader(f); 623 switch (choice) { 624 case '0': // rsgApiStructs.h 625 { 626 fprintf(f, "\n"); 627 fprintf(f, "#include \"rsContext.h\"\n"); 628 fprintf(f, "#include \"rsFifo.h\"\n"); 629 fprintf(f, "\n"); 630 fprintf(f, "namespace android {\n"); 631 fprintf(f, "namespace renderscript {\n"); 632 printStructures(f); 633 printFuncDecls(f, "rsi_", 1); 634 printPlaybackFuncs(f, "rsp_"); 635 fprintf(f, "\n\ntypedef struct RsPlaybackRemoteHeaderRec {\n"); 636 fprintf(f, " uint32_t command;\n"); 637 fprintf(f, " uint32_t size;\n"); 638 fprintf(f, "} RsPlaybackRemoteHeader;\n\n"); 639 fprintf(f, "typedef void (*RsPlaybackLocalFunc)(Context *, const void *, size_t sizeBytes);\n"); 640 fprintf(f, "typedef void (*RsPlaybackRemoteFunc)(Context *, ThreadIO *);\n"); 641 fprintf(f, "extern RsPlaybackLocalFunc gPlaybackFuncs[%i];\n", apiCount + 1); 642 fprintf(f, "extern RsPlaybackRemoteFunc gPlaybackRemoteFuncs[%i];\n", apiCount + 1); 643 644 fprintf(f, "}\n"); 645 fprintf(f, "}\n"); 646 } 647 break; 648 649 case '1': // rsgApiFuncDecl.h 650 { 651 printFuncDecls(f, "rs", 0); 652 } 653 break; 654 655 case '2': // rsgApi.cpp 656 { 657 printApiCpp(f); 658 } 659 break; 660 661 case '3': // rsgApiReplay.cpp 662 { 663 printFileHeader(f); 664 printPlaybackCpp(f); 665 } 666 break; 667 668 case '4': // rsgApiStream.cpp 669 { 670 printFileHeader(f); 671 printPlaybackCpp(f); 672 } 673 674 case '5': // rsgApiStreamReplay.cpp 675 { 676 printFileHeader(f); 677 printPlaybackCpp(f); 678 } 679 break; 680 } 681 fclose(f); 682 return 0; 683} 684