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