00001 #include "For.h"
00002 #include "IntExpr.h"
00003
00004 namespace xi {
00005
00006 ForConstruct::ForConstruct(IntExprConstruct* decl, IntExprConstruct* pred,
00007 IntExprConstruct* advance, SdagConstruct* body)
00008 : BlockConstruct(SFOR, 0, decl, pred, advance, 0, body, 0) {
00009 label_str = "for";
00010 }
00011
00012 void ForConstruct::generateCode(XStr& decls, XStr& defs, Entry* entry) {
00013 sprintf(nameStr, "%s%s", CParsedFile::className->charstar(), label->charstar());
00014
00015 generateClosureSignature(decls, defs, entry, false, "void", label, false, encapState);
00016 #if CMK_BIGSIM_CHARM
00017 generateBeginTime(defs);
00018 #endif
00019
00020 int indent = unravelClosuresBegin(defs);
00021
00022 indentBy(defs, indent);
00023 defs << con1->text << ";\n";
00024
00025 #if CMK_BIGSIM_CHARM
00026 generateEventBracket(defs, SFOR);
00027 #endif
00028 indentBy(defs, indent);
00029 defs << "if (" << con2->text << ") {\n";
00030 indentBy(defs, indent + 1);
00031 generateCall(defs, encapStateChild, encapStateChild, constructs->front()->label);
00032 indentBy(defs, indent);
00033 defs << "} else {\n";
00034 indentBy(defs, indent + 1);
00035 generateCall(defs, encapState, encapState, next->label, nextBeginOrEnd ? 0 : "_end");
00036 indentBy(defs, indent);
00037 defs << "}\n";
00038
00039 unravelClosuresEnd(defs);
00040
00041 endMethod(defs);
00042
00043
00044 sprintf(nameStr, "%s%s", CParsedFile::className->charstar(), label->charstar());
00045 strcat(nameStr, "_end");
00046
00047 generateClosureSignature(decls, defs, entry, false, "void", label, true,
00048 encapStateChild);
00049 #if CMK_BIGSIM_CHARM
00050 generateBeginTime(defs);
00051 #endif
00052 indent = unravelClosuresBegin(defs);
00053
00054 indentBy(defs, indent);
00055 defs << con3->text << ";\n";
00056 indentBy(defs, indent);
00057 defs << "if (" << con2->text << ") {\n";
00058 indentBy(defs, indent + 1);
00059 generateCall(defs, encapStateChild, encapStateChild, constructs->front()->label);
00060 indentBy(defs, indent);
00061 defs << "} else {\n";
00062 #if CMK_BIGSIM_CHARM
00063 generateEventBracket(defs, SFOR_END);
00064 #endif
00065 indentBy(defs, indent + 1);
00066 generateCall(defs, encapState, encapState, next->label, nextBeginOrEnd ? 0 : "_end");
00067 indentBy(defs, indent);
00068 defs << "}\n";
00069
00070 unravelClosuresEnd(defs);
00071
00072 endMethod(defs);
00073
00074 generateChildrenCode(decls, defs, entry);
00075 }
00076
00077 void ForConstruct::numberNodes() {
00078 nodeNum = numFors++;
00079 SdagConstruct::numberNodes();
00080 }
00081
00082 }