00001 #include "Serial.h"
00002
00003 namespace xi {
00004
00005 extern void RemoveSdagComments(char* str);
00006
00007 SerialConstruct::SerialConstruct(const char* code, const char* trace_name, int line_no)
00008 : BlockConstruct(SSERIAL, NULL, 0, 0, 0, 0, 0, 0), line_no_(line_no) {
00009 char* tmp = strdup(code);
00010 text = new XStr(tmp);
00011 free(tmp);
00012
00013 if (trace_name) {
00014 tmp = strdup(trace_name);
00015 tmp[strlen(tmp) - 1] = 0;
00016 traceName = new XStr(tmp + 1);
00017 free(tmp);
00018 }
00019
00020 label_str = "serial";
00021 }
00022
00023 void SerialConstruct::propagateStateToChildren(std::list<EncapState*> encap,
00024 std::list<CStateVar*>& stateVarsChildren,
00025 std::list<CStateVar*>& wlist,
00026 int uniqueVarNum) {}
00027
00028 void SerialConstruct::generateCode(XStr& decls, XStr& defs, Entry* entry) {
00029 generateClosureSignature(decls, defs, entry, false, "void", label, false, encapState);
00030
00031 #if CMK_BIGSIM_CHARM
00032 sprintf(nameStr, "%s%s", CParsedFile::className->charstar(), label->charstar());
00033 generateBeginExec(defs, nameStr);
00034 #endif
00035
00036 generateTraceBeginCall(defs, 1);
00037
00038 char* str = text->get_string();
00039 bool hasCode = false;
00040
00041 while (*str != '\0') {
00042 if (*str != '\n' && *str != ' ' && *str != '\t') {
00043 hasCode = true;
00044 break;
00045 }
00046 str++;
00047 }
00048
00049 if (hasCode) {
00050 int indent = unravelClosuresBegin(defs);
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 indentBy(defs, indent);
00061 defs << "{ // begin serial block\n";
00062 defs << "#line " << line_no_ << " \"" << cur_file << "\"\n";
00063 defs << text << "\n";
00064 defs << "#"
00065 << "\n";
00066 indentBy(defs, indent);
00067 defs << "} // end serial block\n";
00068
00069 unravelClosuresEnd(defs);
00070 }
00071
00072 generateTraceEndCall(defs, 1);
00073
00074 #if CMK_BIGSIM_CHARM
00075 generateEndExec(defs);
00076 #endif
00077
00078 indentBy(defs, 1);
00079 generateCall(defs, encapState, encapState, next->label, nextBeginOrEnd ? 0 : "_end");
00080 endMethod(defs);
00081 }
00082
00083 void SerialConstruct::generateTrace() {
00084 char traceText[1024];
00085 if (traceName) {
00086 sprintf(traceText, "%s_%s", CParsedFile::className->charstar(),
00087 traceName->charstar());
00088
00089 for (unsigned int i = 0; i < strlen(traceText); i++)
00090 if (traceText[i] == ' ' || traceText[i] == '\t') traceText[i] = '_';
00091 } else {
00092 sprintf(traceText, "%s%s", CParsedFile::className->charstar(), label->charstar());
00093 }
00094 traceName = new XStr(traceText);
00095
00096 if (con1) con1->generateTrace();
00097 }
00098
00099 void SerialConstruct::numberNodes(void) {
00100 nodeNum = numSerials++;
00101 SdagConstruct::numberNodes();
00102 }
00103
00104 }