2 #include "GroupBlock.h"
3 #include "ReferenceBlock.h"
4 #include "FunctionalBlock.h"
8 topGroup = new GroupBlock(NULL);
9 topGroup->setName("top group");
10 groups.append(topGroup);
18 QList<AbstractInterface *> Graph::getOutsideInterfaces() {
19 return topGroup->getInterfaces();
22 GroupBlock* Graph::createChildGroupBlock(GroupBlock* parent) {
23 GroupBlock* b = new GroupBlock(parent);
28 bool Graph::removeGroupBlock(GroupBlock *group) {
29 group->removeAllBlocks();
30 GroupBlock* parent = AB_TO_GRP(group->getParent());
31 parent->removeBlock(group);
32 groups.removeAll(group);
35 GroupBlock* Graph::getGroupBlockByName(QString name) {
36 foreach(GroupBlock* group, groups) {
37 if (group->getName() == name) return group;
42 FunctionalBlock* Graph::createFunctionalBlock(GroupBlock* group, ReferenceBlock* ref) {
44 FunctionalBlock* newBlock = new FunctionalBlock(group,ref);
46 group->addBlock(newBlock);
51 FunctionalBlock* Graph::duplicateFunctionalBlock(FunctionalBlock *block) {
53 ReferenceBlock* ref = block->getReference();
54 GroupBlock* group = AB_TO_GRP(block->getParent());
56 // adding to the graph
57 FunctionalBlock* newBlock = createFunctionalBlock(group,ref);
62 bool Graph::removeFunctionalBlock(FunctionalBlock* block) {
63 GroupBlock* group = AB_TO_GRP(block->getParent());
64 group->removeBlock(block);
68 FunctionalBlock* Graph::getFunctionalBlockByName(QString name, GroupBlock* parent) {
69 FunctionalBlock* block = NULL;
71 block = AB_TO_FUN(parent->getFunctionalBlockByName(name));
74 foreach(GroupBlock* group, groups) {
75 block = AB_TO_FUN(group->getFunctionalBlockByName(name));
76 if (block != NULL) return block;
82 FunctionalBlock* Graph::createSourceBlock(ReferenceBlock* ref) {
84 FunctionalBlock* newBlock = new FunctionalBlock(NULL,ref);
86 sources.append(newBlock);
90 FunctionalBlock* Graph::duplicateSourceBlock(FunctionalBlock *block) {
92 ReferenceBlock* ref = block->getReference();
93 GroupBlock* group = AB_TO_GRP(block->getParent());
95 // adding to the graph
96 FunctionalBlock* newBlock = createSourceBlock(ref);
100 FunctionalBlock* Graph::getSourceBlockByName(QString name) {
101 foreach(FunctionalBlock* block, sources) {
102 if (block->getName() == name) return block;
107 bool Graph::removeSourceBlock(FunctionalBlock *block) {
108 sources.removeAll(block);
112 void Graph::createPatterns() throw(Exception) {
114 foreach(AbstractBlock* block, sources) {
115 FunctionalBlock* funBlock = AB_TO_FUN(block);
117 funBlock->createPatterns();
124 foreach(AbstractBlock* block, groups) {
125 GroupBlock* group = AB_TO_GRP(block);
126 foreach(AbstractBlock* inBlock, group->getBlocks()) {
127 if (inBlock->isFunctionalBlock()) {
128 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
130 funBlock->createPatterns();
140 void Graph::resetPatternComputed() {
141 foreach(AbstractBlock* block, sources) {
142 block->setPatternComputed(false);
144 foreach(AbstractBlock* block, groups) {
145 GroupBlock* group = AB_TO_GRP(block);
146 group->setPatternComputed(false);
147 foreach(AbstractBlock* inBlock, group->getBlocks()) {
148 inBlock->setPatternComputed(false);
153 bool Graph::computeOutputPatterns(int nbExec) {
159 cerr << qPrintable(e.getMessage()) << endl;
163 resetPatternComputed();
164 // search for all block that are generators.
165 QList<FunctionalBlock*> generators;
166 generators.append(sources);
167 foreach(AbstractBlock* block, groups) {
168 GroupBlock* group = AB_TO_GRP(block);
169 foreach(AbstractBlock* inBlock, group->getBlocks()) {
170 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
171 if ((inBlock->isFunctionalBlock()) && (inBlock->isGeneratorBlock())) {
172 generators.append(funBlock);
176 // search for maximum PP length
178 foreach(FunctionalBlock* block, generators) {
179 if (block->getProductionPatternLength() > maxPP) maxPP = block->getProductionPatternLength();
181 // compute output for generators
182 int maxExecLen = maxPP*nbExec;
183 foreach(FunctionalBlock* block, generators) {
184 int d = block->getProductionPatternLength();
185 block->computeOutputPattern((maxExecLen+d-1)/d);
187 // compute output for top group
189 topGroup->computeOutputPattern();
192 cerr << qPrintable(e.getMessage()) << endl;