00001 #ifndef _SDAG_CONSTRUCT_H
00002 #define _SDAG_CONSTRUCT_H
00003
00004 #include <list>
00005
00006 #include "sdag-globals.h"
00007 #include "xi-util.h"
00008
00009 #include "EToken.h"
00010
00011 namespace xi {
00012
00013 class Entry;
00014 class EntryList;
00015 class EncapState;
00016 class WhenConstruct;
00017 class CStateVar;
00018 class ParamList;
00019 class CEntry;
00020 class Chare;
00021
00022
00023
00024 extern void generateClosureSignature(XStr& decls, XStr& defs, const Chare* chare,
00025 bool declareStatic, const char* returnType,
00026 const XStr* name, bool isEnd,
00027 std::list<EncapState*> params, int numRefs = 0);
00028 extern void generateClosureSignature(XStr& decls, XStr& defs, const Entry* entry,
00029 bool declareStatic, const char* returnType,
00030 const XStr* name, bool isEnd,
00031 std::list<EncapState*> params, int numRefs = 0);
00032 extern void endMethod(XStr& op);
00033
00034
00035 class SdagConstruct {
00036 private:
00037 void generateOverlap(XStr& decls, XStr& defs, Entry* entry);
00038 void generateWhile(XStr& decls, XStr& defs, Entry* entry);
00039 void generateFor(XStr& decls, XStr& defs, Entry* entry);
00040 void generateIf(XStr& decls, XStr& defs, Entry* entry);
00041 void generateElse(XStr& decls, XStr& defs, Entry* entry);
00042 void generateForall(XStr& decls, XStr& defs, Entry* entry);
00043 void generateOlist(XStr& decls, XStr& defs, Entry* entry);
00044 void generateSdagEntry(XStr& decls, XStr& defs, Entry* entry);
00045 void generateSlist(XStr& decls, XStr& defs, Entry* entry);
00046 void generateCaseList(XStr& decls, XStr& defs, Entry* entry);
00047
00048 protected:
00049 void generateCall(XStr& op, std::list<EncapState*>& cur, std::list<EncapState*>& next,
00050 const XStr* name, const char* nameSuffix = 0);
00051 void generateTraceBeginCall(XStr& defs, int indent);
00052 void generateBeginTime(XStr& defs);
00053 void generateEventBracket(XStr& defs, int eventType);
00054 void generateListEventBracket(XStr& defs, int eventType);
00055 void generateChildrenCode(XStr& decls, XStr& defs, Entry* entry);
00056 void generateChildrenEntryList(std::list<CEntry*>& CEntrylist, WhenConstruct* thisWhen);
00057 void propagateStateToChildren(std::list<EncapState*>, std::list<CStateVar*>&,
00058 std::list<CStateVar*>&, int);
00059 std::list<SdagConstruct*>* constructs;
00060 std::list<CStateVar*>* stateVars;
00061 std::list<EncapState*> encapState, encapStateChild;
00062 std::list<CStateVar*>* stateVarsChildren;
00063 const char* label_str;
00064 Entry* entry;
00065
00066 public:
00067 int unravelClosuresBegin(XStr& defs, bool child = false);
00068 void unravelClosuresEnd(XStr& defs, bool child = false);
00069
00070 int nodeNum;
00071 XStr* label;
00072 XStr* counter;
00073 EToken type;
00074 char nameStr[128];
00075 XStr* traceName;
00076 SdagConstruct* next;
00077 ParamList* param;
00078
00079 XStr* text;
00080 int nextBeginOrEnd;
00081 EntryList* elist;
00082 SdagConstruct *con1, *con2, *con3, *con4;
00083 SdagConstruct(EToken t, SdagConstruct* construct1);
00084
00085 SdagConstruct(EToken t, SdagConstruct* construct1, SdagConstruct* aList);
00086
00087 SdagConstruct(EToken t, XStr* txt, SdagConstruct* c1, SdagConstruct* c2,
00088 SdagConstruct* c3, SdagConstruct* c4, SdagConstruct* constructAppend,
00089 EntryList* el);
00090
00091 SdagConstruct(EToken t, const char* str);
00092 SdagConstruct(EToken t);
00093 SdagConstruct(EToken t, XStr* txt);
00094 SdagConstruct(EToken t, const char* entryStr, const char* codeStr, ParamList* pl);
00095
00096 virtual ~SdagConstruct();
00097
00098 void init(EToken& t);
00099 void setEntry(Entry* e);
00100 virtual void numberNodes();
00101 virtual void labelNodes();
00102 XStr* createLabel(const char* str, int nodeNum);
00103 virtual void generateEntryList(std::list<CEntry*>&, WhenConstruct*);
00104 void propagateState(int);
00105 virtual void propagateState(std::list<EncapState*>, std::list<CStateVar*>&,
00106 std::list<CStateVar*>&, int);
00107 virtual void generateCode(XStr& decls, XStr& defs, Entry* entry);
00108 void setNext(SdagConstruct*, int);
00109 void buildTypes(std::list<EncapState*>& state);
00110
00111
00112 virtual void generateTrace();
00113 void generateRegisterEp(XStr& defs);
00114 void generateTraceEp(XStr& decls, XStr& defs, Chare* chare);
00115 static void generateTraceEndCall(XStr& defs, int indent);
00116 static void generateTlineEndCall(XStr& defs);
00117 static void generateBeginExec(XStr& defs, const char* name);
00118 static void generateEndExec(XStr& defs);
00119 static void generateEndSeq(XStr& defs);
00120 static void generateDummyBeginExecute(XStr& defs, int indent, Entry* entry);
00121 };
00122
00123 }
00124
00125 #endif // ifndef _SDAG_CONSTRUCT_H