00001 #include "xi-Chare.h"
00002 #include "xi-Member.h"
00003 #include "xi-Value.h"
00004
00005 namespace xi {
00006
00007 XStr makeIdent(const XStr& in);
00008
00009 extern int fortranMode;
00010
00011
00012
00013
00014
00015 XStr Member::makeDecl(const XStr& returnType, int forProxy, bool isStatic, XStr fwdStr) {
00016 XStr str;
00017
00018 if (container->isTemplated()) str << container->tspec(false) << "\n";
00019 const bool doFwd = fwdStr != "";
00020 if (tspec || doFwd) {
00021 str << "template <";
00022 if (tspec) {
00023 tspec->genLong(str, false);
00024 if (doFwd)
00025 str << ", ";
00026 }
00027 if (doFwd)
00028 str << fwdStr;
00029 str << ">\n";
00030 }
00031 if (isStatic) str << "static ";
00032 str << returnType << " ";
00033 if (forProxy == 1)
00034 str << container->proxyName();
00035 else if (forProxy == 0)
00036 str << container->indexName();
00037 else
00038 str << container->sectionName();
00039 return str;
00040 }
00041
00042 void Readonly::print(XStr& str) {
00043 if (external) str << "extern ";
00044 str << "readonly ";
00045 if (msg) str << "message ";
00046 type->print(str);
00047 if (msg)
00048 str << " *";
00049 else
00050 str << " ";
00051 str << name;
00052 if (dims) dims->print(str);
00053 str << ";\n";
00054 }
00055
00056 void Readonly::genDefs(XStr& str) {
00057 str << "/* DEFS: ";
00058 print(str);
00059 str << " */\n";
00060 if (!container && !strchr(name, ':')) {
00061 str << "extern ";
00062 type->print(str);
00063 if (msg) str << "*";
00064 str << " " << name;
00065 if (dims) dims->print(str);
00066 str << ";\n";
00067 }
00068
00069 if (!msg) {
00070 templateGuardBegin(false, str);
00071 str << "extern \"C\" void __xlater_roPup_" << makeIdent(qName());
00072 str << "(void *_impl_pup_er) {\n";
00073 str << " PUP::er &_impl_p=*(PUP::er *)_impl_pup_er;\n";
00074 if (dims) {
00075
00076 str <<"#if !CMK_ONESIDED_RO_DISABLE && CMK_ONESIDED_IMPL\n";
00077
00078 str <<" if(";
00079 dims->printValueProduct(str);
00080 str <<" * sizeof(";
00081 type->print(str);
00082 str << ") >= CMK_ONESIDED_RO_THRESHOLD) {\n";
00083 str <<" CkNcpyBuffer myBuffer(& "<< qName();
00084 dims->printZeros(str);
00085 str <<", (";
00086 dims->printValueProduct(str);
00087 str <<" * sizeof(";
00088 type->print(str);
00089 str <<")), CK_BUFFER_REG);\n";
00090 str <<" if(_impl_p.isPacking() || _impl_p.isSizing()) {\n";
00091 str <<" _impl_p|myBuffer;\n";
00092 str <<" if(_impl_p.isSizing())\n";
00093 str <<" readonlyUpdateNumops();\n";
00094 str <<" else\n";
00095 str <<" readonlyCreateOnSource(myBuffer);\n";
00096 str <<" }\n";
00097 str <<" if(_impl_p.isPacking()) {\n";
00098 str <<" PUP::toMem &_impl_p_toMem = *(PUP::toMem *)_impl_pup_er;\n";
00099 str <<" envelope *env = UsrToEnv(_impl_p_toMem.get_orig_pointer());\n";
00100 str <<" CMI_ZC_MSGTYPE(env) = CMK_ZC_BCAST_SEND_MSG;\n";
00101 str <<" }\n";
00102 str <<" if(_impl_p.isUnpacking()) {\n";
00103 str <<" PUP::fromMem &_impl_p_fromMem = *(PUP::fromMem *)_impl_pup_er;\n";
00104 str <<" char *ptr = _impl_p_fromMem.get_current_pointer();\n";
00105 str <<" PUP::toMem _impl_p_toMem = (PUP::toMem)((void *)ptr);\n";
00106 str <<" envelope *env = UsrToEnv(_impl_p_fromMem.get_orig_pointer());\n";
00107 str <<" CkNcpyBuffer srcBuffer;\n";
00108 str <<" _impl_p|srcBuffer;\n";
00109 str <<" _impl_p_toMem|myBuffer;\n";
00110 str <<" readonlyGet(srcBuffer, myBuffer, (void *)env);\n";
00111 str <<" }\n";
00112 str <<" } else\n";
00113 str <<"#endif\n";
00114 str << " {\n";
00115 str << " _impl_p(&" << qName();
00116 dims->printZeros(str);
00117 str << ", (";
00118 dims->printValueProduct(str);
00119 str << ") );\n";
00120 str << " }\n";
00121 } else {
00122 if(strcmp("vector",type->getBaseName()) == 0) {
00123
00124 str <<"#if !CMK_ONESIDED_RO_DISABLE && CMK_ONESIDED_IMPL\n";
00125 NamedType *nType = (NamedType *)type;
00126
00127
00128 str <<" bool vecUsesZC = false;\n";
00129 str <<" if(_impl_p.isPacking() || _impl_p.isSizing()) {\n";
00130
00131 str <<" vecUsesZC = (" << qName() <<".size()";
00132 str <<" * sizeof(" << nType->getTparams() <<")";
00133 str <<" >= CMK_ONESIDED_RO_THRESHOLD);\n";
00134 str <<" }\n";
00135
00136 str <<" _impl_p|vecUsesZC;\n";
00137
00138 str <<" if(vecUsesZC) {\n";
00139 str <<" if(_impl_p.isPacking() || _impl_p.isSizing()) {\n";
00140 str <<" CkNcpyBuffer myBuffer("<< qName() << ".data()";
00141 str <<", " << "sizeof(" << nType->getTparams() << ") * "<< qName() <<".size()";
00142 str <<", CK_BUFFER_REG);\n";
00143 str <<" _impl_p|myBuffer;\n";
00144 str <<" if(_impl_p.isSizing())\n";
00145 str <<" readonlyUpdateNumops();\n";
00146 str <<" else\n";
00147 str <<" readonlyCreateOnSource(myBuffer);\n";
00148 str <<" }\n";
00149 str <<" if(_impl_p.isPacking()) {\n";
00150 str <<" PUP::toMem &_impl_p_toMem_orig = *(PUP::toMem *)_impl_pup_er;\n";
00151 str <<" envelope *env = UsrToEnv(_impl_p_toMem_orig.get_orig_pointer());\n";
00152 str <<" CMI_ZC_MSGTYPE(env) = CMK_ZC_BCAST_SEND_MSG;\n";
00153 str <<" }\n";
00154 str <<" if(_impl_p.isUnpacking()) {\n";
00155 str <<" PUP::fromMem &_impl_p_fromMem = *(PUP::fromMem *)_impl_pup_er;\n";
00156 str <<" envelope *env = UsrToEnv(_impl_p_fromMem.get_orig_pointer());\n";
00157 str <<" char *ptr = _impl_p_fromMem.get_current_pointer();\n";
00158 str <<" PUP::toMem _impl_p_toMem = (PUP::toMem)((void *)ptr);\n";
00159 str <<" CkNcpyBuffer srcBuffer;\n";
00160 str <<" _impl_p|srcBuffer;\n";
00161 str <<" size_t nElem = ";
00162 str <<"(srcBuffer.cnt)/sizeof("<<nType->getTparams()<<");\n";
00163 str <<" " << qName() <<".resize(nElem);\n";
00164 str <<" " << qName() <<".shrink_to_fit();\n";
00165 str <<" CkNcpyBuffer myBuffer("<< qName() << ".data()";
00166 str <<", " << "srcBuffer.cnt, CK_BUFFER_REG);\n";
00167 str <<" _impl_p_toMem|myBuffer;\n";
00168 str <<" readonlyGet(srcBuffer, myBuffer, (void *)env);\n";
00169 str <<" }\n";
00170 str <<" } else\n";
00171 str <<"#endif\n";
00172 str <<" {\n";
00173 str <<" _impl_p|" << qName() << ";\n";
00174 str <<" }\n";
00175 } else {
00176 str <<" _impl_p|" << qName() << ";\n";
00177 }
00178 }
00179 str << "}\n";
00180 templateGuardEnd(str);
00181 }
00182
00183 if (fortranMode) {
00184 str << "extern \"C\" void " << fortranify("set_", name) << "(int *n) { " << name
00185 << " = *n; }\n";
00186 str << "extern \"C\" void " << fortranify("get_", name) << "(int *n) { *n = " << name
00187 << "; }\n";
00188 }
00189 }
00190
00191 void Readonly::genReg(XStr& str) {
00192 if (external) return;
00193 if (msg) {
00194 if (dims) XLAT_ERROR_NOCOL("readonly message cannot be an array", line);
00195 str << " CkRegisterReadonlyMsg(\"" << qName() << "\",\"" << type << "\",";
00196 str << "(void **)&" << qName() << ");\n";
00197 } else {
00198 str << " CkRegisterReadonly(\"" << qName() << "\",\"" << type << "\",";
00199 str << "sizeof(" << qName() << "),(void *) &" << qName() << ",";
00200 str << "__xlater_roPup_" << makeIdent(qName()) << ");\n";
00201 }
00202 }
00203
00204 XStr Readonly::qName(void) const {
00205 XStr ret;
00206 if (container) ret << container->baseName() << "::";
00207 ret << name;
00208 return ret;
00209 }
00210
00211 Readonly::Readonly(int l, Type* t, const char* n, ValueList* d, int m)
00212 : msg(m), type(t), name(n) {
00213 line = l;
00214 dims = d;
00215 setChare(0);
00216 }
00217
00218 void Readonly::genDecls(XStr& str) {
00219 str << "/* DECLS: ";
00220 print(str);
00221 str << " */\n";
00222 }
00223
00224 void Readonly::genIndexDecls(XStr& str) {
00225 str << "/* DECLS: ";
00226 print(str);
00227 str << " */\n";
00228 }
00229
00230 void InitCall::setAccel() { isAccelFlag = 1; }
00231 void InitCall::clearAccel() { isAccelFlag = 0; }
00232 int InitCall::isAccel() { return isAccelFlag; }
00233
00234
00235 PUPableClass::PUPableClass(int l, NamedType* type_, PUPableClass* next_)
00236 : type(type_), next(next_) {
00237 line = l;
00238 setChare(0);
00239 }
00240 void PUPableClass::print(XStr& str) {
00241 str << " PUPable " << type << ";\n";
00242 if (next) next->print(str);
00243 }
00244 void PUPableClass::genDefs(XStr& str) {
00245 bool isTemplate = type->isTemplated();
00246 templateGuardBegin(isTemplate, str);
00247 if (isTemplate) {
00248 str << " #define _CHARMXI_CLASS_NAME " << type << "\n";
00249 str << " PUPable_def_template(_CHARMXI_CLASS_NAME)\n";
00250 str << " #undef _CHARMXI_CLASS_NAME\n";
00251 } else {
00252 str << " PUPable_def(" << type << ")\n";
00253 }
00254 templateGuardEnd(str);
00255 if (next) next->genDefs(str);
00256 }
00257 void PUPableClass::genReg(XStr& str) {
00258 if (type->isTemplated()) {
00259 str << " #define _CHARMXI_CLASS_NAME " << type << "\n";
00260 str << " PUPable_reg2(_CHARMXI_CLASS_NAME,\"" << type << "\");\n";
00261 str << " #undef _CHARMXI_CLASS_NAME\n";
00262 } else {
00263 str << " PUPable_reg(" << type << ");\n";
00264 }
00265 if (next) next->genReg(str);
00266 }
00267
00268
00269 int PUPableClass::genAccels_spe_c_funcBodies(XStr& str) {
00270 int rtn = 0;
00271 if (next) {
00272 rtn += next->genAccels_spe_c_funcBodies(str);
00273 }
00274 return rtn;
00275 }
00276
00277 void PUPableClass::genAccels_spe_c_regFuncs(XStr& str) {
00278 if (next) {
00279 next->genAccels_spe_c_regFuncs(str);
00280 }
00281 }
00282
00283 void PUPableClass::genAccels_spe_c_callInits(XStr& str) {
00284 if (next) {
00285 next->genAccels_spe_c_callInits(str);
00286 }
00287 }
00288
00289 void PUPableClass::genAccels_spe_h_includes(XStr& str) {
00290 if (next) {
00291 next->genAccels_spe_h_includes(str);
00292 }
00293 }
00294
00295 void PUPableClass::genAccels_spe_h_fiCountDefs(XStr& str) {
00296 if (next) {
00297 next->genAccels_spe_h_fiCountDefs(str);
00298 }
00299 }
00300
00301 void PUPableClass::genAccels_ppe_c_regFuncs(XStr& str) {
00302 if (next) {
00303 next->genAccels_ppe_c_regFuncs(str);
00304 }
00305 }
00306
00307
00308 InitCall::InitCall(int l, const char* n, int nodeCall) : name(n) {
00309 line = l;
00310 setChare(0);
00311 isNodeCall = nodeCall;
00312
00313
00314 isAccelFlag = 0;
00315 }
00316 void InitCall::print(XStr& str) { str << " initcall void " << name << "(void);\n"; }
00317 void InitCall::genReg(XStr& str) {
00318 str << " _registerInitCall(";
00319 if (container) str << container->baseName() << "::";
00320 str << name;
00321 str << "," << isNodeCall << ");\n";
00322 }
00323
00324 void InitCall::genAccels_spe_c_callInits(XStr& str) {
00325 if (isAccel()) {
00326 str << " " << name << "();\n";
00327 }
00328 }
00329
00330
00331 IncludeFile::IncludeFile(int l, const char* n) : name(n) {
00332 line = l;
00333 setChare(0);
00334 }
00335 void IncludeFile::print(XStr& str) { str << " include " << name << ";\n"; }
00336 void IncludeFile::genDecls(XStr& str) { str << "#include " << name << "\n"; }
00337
00338
00339 ClassDeclaration::ClassDeclaration(int l, const char* n) : name(n) {
00340 line = l;
00341 setChare(0);
00342 }
00343 void ClassDeclaration::print(XStr& str) { str << " class " << name << ";\n"; }
00344 void ClassDeclaration::genDecls(XStr& str) { str << "class " << name << ";\n"; }
00345
00346
00347 XStr makeIdent(const XStr& in) {
00348 XStr ret;
00349 const char* i = in.get_string_const();
00350 while (*i != 0) {
00351
00352 if (*i == ':')
00353 ret << "_QColon_";
00354 else if (*i == ' ')
00355 ret << "_QSpace_";
00356 else if (*i == '+')
00357 ret << "_QPlus_";
00358 else if (*i == '-')
00359 ret << "_QMinus_";
00360 else if (*i == '*')
00361 ret << "_QTimes_";
00362 else if (*i == '/')
00363 ret << "_QSlash_";
00364 else if (*i == '%')
00365 ret << "_QPercent_";
00366 else if (*i == '&')
00367 ret << "_QAmpersand_";
00368 else if (*i == '.')
00369 ret << "_QDot_";
00370 else if (*i == ',')
00371 ret << "_QComma_";
00372 else if (*i == '\'')
00373 ret << "_QSQuote_";
00374 else if (*i == '\"')
00375 ret << "_QQuote_";
00376 else if (*i == '(')
00377 ret << "_QLparen_";
00378 else if (*i == ')')
00379 ret << "_QRparen_";
00380 else if (*i == '<')
00381 ret << "_QLess_";
00382 else if (*i == '>')
00383 ret << "_QGreater_";
00384 else if (*i == '{')
00385 ret << "_QLbrace_";
00386 else if (*i == '}')
00387 ret << "_QRbrace_";
00388 else
00389 ret << *i;
00390 i++;
00391 }
00392 return ret;
00393 }
00394
00395 }