00001 #include "CStateVar.h"
00002 #include "SdagEntry.h"
00003 #include "xi-Chare.h"
00004 #include "xi-Entry.h"
00005 #include "xi-Parameter.h"
00006 #include <list>
00007
00008 namespace xi {
00009
00010 SdagEntryConstruct::SdagEntryConstruct(SdagConstruct* body)
00011 : SdagConstruct(SSDAGENTRY, body) {}
00012
00013 SdagEntryConstruct::SdagEntryConstruct(SListConstruct* body)
00014 : SdagConstruct(SSDAGENTRY, body) {}
00015
00016 void SdagEntryConstruct::generateCode(XStr& decls, XStr& defs, XStr &sdagFuncName, bool isDummy) {
00017 XStr signature;
00018 signature << sdagFuncName;
00019 signature << "(";
00020 if (stateVars) {
00021 int count = 0;
00022 for (std::list<CStateVar*>::iterator iter = stateVars->begin();
00023 iter != stateVars->end(); ++iter) {
00024 CStateVar& var = **iter;
00025 if (var.isVoid != 1) {
00026 if (count != 0) signature << ", ";
00027 if (var.byConst) signature << "const ";
00028 if (var.type != 0) signature << var.type << " ";
00029 if (var.arrayLength != NULL) signature << "* ";
00030 if (var.declaredRef) signature << "& ";
00031 if (var.name != 0) signature << var.name;
00032 count++;
00033 }
00034 }
00035 }
00036 signature << ")";
00037
00038 if (isDummy) {
00039 decls << " void " << signature << ";\n";
00040
00041
00042 generateLocalWrapper(decls, defs, entry->param->isVoid(), signature, entry, stateVars,
00043 con1->text, isDummy);
00044 return;
00045 }
00046
00047 if (!entry->param->isVoid()) {
00048 decls << " void " << signature << ";\n";
00049 }
00050
00051
00052 if (entry->paramIsMarshalled() && !entry->param->isVoid())
00053 generateLocalWrapper(decls, defs, entry->param->isVoid(), signature, entry, stateVars,
00054 con1->text);
00055
00056 generateClosureSignature(decls, defs, entry, false, "void", (const XStr *)&sdagFuncName, false,
00057 encapState);
00058 }
00059
00060 void SdagEntryConstruct::generateCode(XStr& decls, XStr& defs, Entry* entry) {
00061 if (entry->isConstructor()) {
00062 std::cerr << cur_file << ":" << entry->getLine()
00063 << ": Chare constructor cannot be defined with SDAG code" << std::endl;
00064 exit(1);
00065 }
00066
00067 buildTypes(encapState);
00068 buildTypes(encapStateChild);
00069
00070 decls << "public:\n";
00071
00072 XStr sdagFuncName;
00073 if(entry->containsWhenConstruct) {
00074
00075 sdagFuncName << con1->text;
00076 generateCode(decls, defs, sdagFuncName, true);
00077 sdagFuncName.clear();
00078
00079
00080 sdagFuncName << "_sdag_fnc_" << con1->text;
00081 generateCode(decls, defs, sdagFuncName);
00082 } else {
00083
00084
00085 sdagFuncName << con1->text;
00086 generateCode(decls, defs, sdagFuncName);
00087 }
00088
00089 #if CMK_BIGSIM_CHARM
00090 generateEndSeq(defs);
00091 #endif
00092 if (!entry->getContainer()->isGroup() || !entry->isConstructor())
00093 generateTraceEndCall(defs, 1);
00094
00095 defs << " if (!__dep.get()) _sdag_init();\n";
00096
00097
00098
00099 if (!entry->paramIsMarshalled() && !entry->param->isVoid()) {
00100
00101 defs << " CmiReference(UsrToEnv(gen0));\n";
00102 }
00103
00104 defs << " ";
00105 generateCall(defs, encapStateChild, encapStateChild, constructs->front()->label);
00106
00107 #if CMK_BIGSIM_CHARM
00108 generateTlineEndCall(defs);
00109 generateBeginExec(defs, "spaceholder");
00110 #endif
00111 if (!entry->getContainer()->isGroup() || !entry->isConstructor())
00112 generateDummyBeginExecute(defs, 1, entry);
00113
00114 endMethod(defs);
00115
00116 decls << "private:\n";
00117 generateClosureSignature(decls, defs, entry, false, "void", con1->text, true,
00118 #if CMK_BIGSIM_CHARM
00119 encapStateChild
00120 #else
00121 encapState
00122 #endif
00123 );
00124
00125 if (!entry->paramIsMarshalled() && !entry->param->isVoid()) {
00126
00127 defs << " CmiFree(UsrToEnv(gen0));\n";
00128 }
00129
00130 endMethod(defs);
00131
00132 generateChildrenCode(decls, defs, entry);
00133 }
00134
00135 void SdagEntryConstruct::numberNodes() {
00136 nodeNum = numSdagEntries++;
00137 SdagConstruct::numberNodes();
00138 }
00139
00140 void SdagEntryConstruct::labelNodes() {
00141 label = createLabel(con1->text->charstar(), -1);
00142 SdagConstruct::labelNodes();
00143 }
00144
00145 }