00001 #ifndef _CHARE_H
00002 #define _CHARE_H
00003
00004 #include <vector>
00005
00006 #include "xi-AstNode.h"
00007 #include "xi-Member.h"
00008 #include "xi-Template.h"
00009
00010 namespace xi {
00011
00012 class CEntry;
00013
00014 struct TramInfo {
00015 std::string type;
00016 std::string name;
00017 std::string itemType;
00018 TramInfo(const char* t, const char* n, const char* i) : type(t), name(n), itemType(i) {}
00019 };
00020
00021
00022 class Chare : public TEntity {
00023 private:
00024 AstChildren<Member>* list;
00025
00026 public:
00027 enum {
00028 CMIGRATABLE = 1 << 2,
00029 CPYTHON = 1 << 3,
00030 CCHARE = 1 << 9,
00031 CMAINCHARE = 1 << 10,
00032 CARRAY = 1 << 11,
00033 CGROUP = 1 << 12,
00034 CNODEGROUP = 1 << 13
00035 };
00036 typedef unsigned int attrib_t;
00037 XStr sdagPUPReg;
00038 XStr sdagDefs, closuresDecl, closuresDef;
00039 std::vector<TramInfo> tramInstances;
00040 bool generateTramInits;
00041 NamedType* type;
00042
00043 protected:
00044 attrib_t attrib;
00045 int hasElement;
00046 forWhom forElement;
00047 int hasSection;
00048
00049 TypeList* bases;
00050 TypeList* bases_CBase;
00051
00052 int entryCount;
00053 int hasSdagEntry;
00054
00055 void genTypedefs(XStr& str);
00056 void genRegisterMethodDef(XStr& str);
00057 void sharedDisambiguation(XStr& str, const XStr& superclass);
00058 void genMemberDecls(XStr& str);
00059
00060 public:
00061 Chare(int ln, attrib_t Nattr, NamedType* t, TypeList* b = 0,
00062 AstChildren<Member>* l = 0);
00063 void genProxyNamesExceptFirst(XStr& str, const char* prefix, const char* middle,
00064 const char* suffix, const char* sep);
00065 void genProxyNames(XStr& str, const char* prefix, const char* middle,
00066 const char* suffix, const char* sep);
00067 void genIndexNames(XStr& str, const char* prefix, const char* middle,
00068 const char* suffix, const char* sep);
00069 void printChareNames();
00070 XStr proxyName(int withTemplates = 1);
00071 XStr indexName(int withTemplates = 1);
00072 XStr sectionName(int withTemplates = 1);
00073 XStr indexList();
00074 XStr baseName(int withTemplates = 1) const {
00075 XStr str;
00076 str << type->getBaseName();
00077 if (withTemplates) str << tvars();
00078 return str;
00079 }
00080 XStr cbaseTType();
00081 int isTemplated(void) { return (templat != 0); }
00082 bool isTemplateDeclaration() { return templat; }
00083 bool isTemplateInstantiation() { return type->isTemplated(); }
00084 int isMigratable(void) { return attrib & CMIGRATABLE; }
00085 int isPython(void) { return attrib & CPYTHON; }
00086 int isMainChare(void) { return attrib & CMAINCHARE; }
00087 int isChare(void) { return attrib & CCHARE; }
00088 int isArray(void) { return attrib & CARRAY; }
00089 int isGroup(void) { return attrib & CGROUP; }
00090 int isNodeGroup(void) { return attrib & CNODEGROUP; }
00091 int isForElement(void) const { return forElement == forIndividual; }
00092 int isForSection(void) const { return forElement == forSection; }
00093 int hasSdag() const { return hasSdagEntry; }
00094 void setSdag(int f) { hasSdagEntry = f; }
00095 forWhom getForWhom(void) const { return forElement; }
00096 void print(XStr& str);
00097 void check();
00098 void genDefs(XStr& str);
00099 void genReg(XStr& str);
00100 void genDecls(XStr& str);
00101 void genGlobalCode(XStr scope, XStr& decls, XStr& defs);
00102 void genRecursivePup(XStr& scopedName, XStr templateSpec, XStr& decls, XStr& defs);
00103 void preprocess();
00104
00105 bool isTramTarget();
00106 void genTramTypes();
00107 void genTramDecls(XStr& str);
00108 void genTramInits(XStr& str);
00109
00110
00111 int genAccels_spe_c_funcBodies(XStr& str) {
00112 int rtn = 0;
00113 if (list) {
00114 rtn += list->genAccels_spe_c_funcBodies(str);
00115 }
00116 return rtn;
00117 }
00118 void genAccels_spe_c_regFuncs(XStr& str) {
00119 if (list) {
00120 list->genAccels_spe_c_regFuncs(str);
00121 }
00122 }
00123 void genAccels_spe_c_callInits(XStr& str) {
00124 if (list) {
00125 list->genAccels_spe_c_callInits(str);
00126 }
00127 }
00128 void genAccels_spe_h_includes(XStr& str) {
00129 if (list) {
00130 list->genAccels_spe_h_includes(str);
00131 }
00132 }
00133 void genAccels_spe_h_fiCountDefs(XStr& str) {
00134 if (list) {
00135 list->genAccels_spe_h_fiCountDefs(str);
00136 }
00137 }
00138 void genAccels_ppe_c_regFuncs(XStr& str) {
00139 if (list) {
00140 list->genAccels_ppe_c_regFuncs(str);
00141 }
00142 }
00143
00144 int nextEntry(void) { return entryCount++; }
00145 virtual void genSubDecls(XStr& str);
00146 virtual void outputClosuresDecl(XStr& str);
00147 virtual void outputClosuresDef(XStr& str);
00148 virtual void genClosureEntryDecls(XStr& str);
00149 virtual void genClosureEntryDefs(XStr& str);
00150 void genPythonDecls(XStr& str);
00151 void genPythonDefs(XStr& str);
00152 virtual char* chareTypeName(void) { return (char*)"chare"; }
00153 virtual char* proxyPrefix(void);
00154 virtual void genSubRegisterMethodDef(XStr& str) { (void)str; }
00155 void lookforCEntry(CEntry* centry);
00156
00157 private:
00158 XStr virtualPupDef(const XStr& name);
00159 };
00160
00161 class MainChare : public Chare {
00162 public:
00163 MainChare(int ln, attrib_t Nattr, NamedType* t, TypeList* b = 0,
00164 AstChildren<Member>* l = 0)
00165 : Chare(ln, Nattr | CMAINCHARE, t, b, l) {}
00166 virtual char* chareTypeName(void) { return (char*)"mainchare"; }
00167 };
00168
00169 class Array : public Chare {
00170 protected:
00171 XStr indexSuffix;
00172 XStr indexType;
00173 public:
00174 Array(int ln, attrib_t Nattr, NamedType* index, NamedType* t, TypeList* b = 0,
00175 AstChildren<Member>* l = 0);
00176 virtual int is1D(void) { return indexSuffix == (const char*)"1D"; }
00177 virtual const char* dim(void) { return indexSuffix.get_string_const(); }
00178 virtual void genSubDecls(XStr& str);
00179 virtual char* chareTypeName(void) { return (char*)"array"; }
00180 bool hasVoidConstructor;
00181 };
00182
00183 class Group : public Chare {
00184 public:
00185 Group(int ln, attrib_t Nattr, NamedType* t, TypeList* b = 0,
00186 AstChildren<Member>* l = 0);
00187 virtual void genSubDecls(XStr& str);
00188 virtual char* chareTypeName(void) { return (char*)"group"; }
00189 virtual void genSubRegisterMethodDef(XStr& str);
00190 };
00191
00192 class NodeGroup : public Group {
00193 public:
00194 NodeGroup(int ln, attrib_t Nattr, NamedType* t, TypeList* b = 0,
00195 AstChildren<Member>* l = 0)
00196 : Group(ln, Nattr | CNODEGROUP, t, b, l) {}
00197 virtual char* chareTypeName(void) { return (char*)"nodegroup"; }
00198 };
00199
00200 }
00201
00202 #endif // ifndef _CHARE_H