00001
00002 #include "interfaceBuilder.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011 namespace Builder {
00012 xi::AstChildren<xi::Module>* generateTestAst() {
00013 File* f = new File();
00014 Module* m = new Module("test", true);
00015
00016 MainChare* mc = new MainChare("Main");
00017 ConsEntry* mccons = new ConsEntry("Main");
00018 mccons->addEntryParameter(new Parameter(new PtrType(new Type("CkArgMsg")), "m"));
00019 mc->addEntry(mccons);
00020
00021 Chare* c = new Chare("Fib");
00022 ConsEntry* cons = new ConsEntry("Fib");
00023 c->addEntry(cons);
00024 Entry* entry1 = new Entry(new Type("void"), "sendValue");
00025 entry1->addEntryParameter(new Parameter(new Type("int"), "value"));
00026 c->addEntry(entry1);
00027
00028 Readonly* ro = new Readonly(new Type("int"), "abc");
00029
00030 m->addModuleEntity(mc);
00031 m->addModuleEntity(c);
00032 m->addModuleEntity(ro);
00033
00034 f->addModule(m);
00035 return f->generateAst();
00036 }
00037
00038 xi::AstChildren<xi::Module>* generateHello1d() {
00039 File* f = new File();
00040 Module* m = new Module("hello", true);
00041
00042 MainChare* mc = new MainChare("Main");
00043 ConsEntry* mccons = new ConsEntry("Main");
00044 mccons->addEntryParameter(new Parameter(new PtrType(new Type("CkArgMsg")), "m"));
00045 mc->addEntry(mccons);
00046 Entry* entryDone = new Entry(new Type("void"), "done");
00047 mc->addEntry(entryDone);
00048
00049 Array* a = new Array("Hello", "1D");
00050 ConsEntry* cons = new ConsEntry("Hello");
00051 a->addEntry(cons);
00052 Entry* entrySayHi = new Entry(new Type("void"), "SayHi");
00053 entrySayHi->addEntryParameter(new Parameter(new Type("int"), "hiNo"));
00054 a->addEntry(entrySayHi);
00055
00056 Readonly* ro1 = new Readonly(new Type("int"), "nElements");
00057 Readonly* ro2 = new Readonly(new Type("CProxy_Main"), "mainProxy");
00058
00059 m->addModuleEntity(mc);
00060 m->addModuleEntity(a);
00061 m->addModuleEntity(ro1);
00062 m->addModuleEntity(ro2);
00063
00064 f->addModule(m);
00065 return f->generateAst();
00066 }
00067
00068 xi::AstChildren<xi::Module>* generateFibSDAG() {
00069 File* f = new File();
00070 Module* m = new Module("fib", true);
00071
00072 MainChare* mc = new MainChare("Main");
00073 ConsEntry* mccons = new ConsEntry("Main");
00074 mccons->addEntryParameter(new Parameter(new PtrType(new Type("CkArgMsg")), "m"));
00075 mc->addEntry(mccons);
00076
00077 Chare* a = new Chare("Fib");
00078 ConsEntry* cons = new ConsEntry("Fib");
00079 cons->addEntryParameter(new Parameter(new Type("int"), "n"));
00080 cons->addEntryParameter(new Parameter(new Type("bool"), "isRoot"));
00081 cons->addEntryParameter(new Parameter(new Type("CProxy_Fib"), "parent"));
00082 a->addEntry(cons);
00083
00084 Entry* entryResponse = new Entry(new Type("void"), "response");
00085 entryResponse->addEntryParameter(new Parameter(new Type("int"), "val"));
00086 a->addEntry(entryResponse);
00087
00088 Entry* entryCalc = new Entry(new Type("void"), "calc");
00089 entryCalc->addEntryParameter(new Parameter(new Type("int"), "n"));
00090
00091 SDAG::Sequence* calcSDAG = new SDAG::Sequence();
00092 SDAG::Serial* constructChildren = new
00093 SDAG::Serial("CProxy_Fib::ckNew(n - 1, false, thisProxy);"
00094 "CProxy_Fib::ckNew(n - 2, false, thisProxy);");
00095 SDAG::Serial* respond = new SDAG::Serial("respond(val + val2);");
00096
00097 SDAG::SEntry* response1 = new SDAG::SEntry("response");
00098 response1->addEntryParameter(new Parameter(new Type("int"), "val"));
00099 SDAG::SEntry* response2 = new SDAG::SEntry("response");
00100 response2->addEntryParameter(new Parameter(new Type("int"), "val2"));
00101
00102 SDAG::When* whenResponse2 = new SDAG::When(new SDAG::Sequence(respond));
00103 whenResponse2->addSEntry(response2);
00104 SDAG::When* whenResponse1 = new SDAG::When(new SDAG::Sequence(whenResponse2));
00105 whenResponse1->addSEntry(response1);
00106
00107 SDAG::Sequence* elseSeq = new SDAG::Sequence();
00108 elseSeq->addConstruct(constructChildren);
00109 elseSeq->addConstruct(whenResponse1);
00110 SDAG::Else* elseGTThresh = new SDAG::Else(elseSeq);
00111
00112 SDAG::Serial* respondSeq = new SDAG::Serial("respond(seqFib(n));");
00113 SDAG::If* ifThesh = new SDAG::If("n < THRESHOLD", respondSeq, elseGTThresh);
00114
00115 calcSDAG->addConstruct(ifThesh);
00116 entryCalc->addSDAG(calcSDAG);
00117
00118 a->addEntry(entryCalc);
00119
00120 m->addModuleEntity(mc);
00121 m->addModuleEntity(a);
00122
00123 f->addModule(m);
00124 return f->generateAst();
00125 }
00126 }
00127
00128 #include "xi-main.h"
00129
00130 int main(int argc, char* argv[]) {
00131
00132 xi::AstChildren<xi::Module>* ast = Builder::generateFibSDAG();
00133 processAst(ast, false, false, 0, 0, "generate", "");
00134 }