2 #include "GroupBlock.h"
3 #include "ReferenceBlock.h"
4 #include "FunctionalBlock.h"
7 topGroup = new GroupBlock(NULL);
8 topGroup->setName("top group");
9 groups.append(topGroup);
17 QList<AbstractInterface *> Graph::getOutsideInterfaces() {
18 return topGroup->getInterfaces();
21 GroupBlock* Graph::createChildGroupBlock(GroupBlock* parent) {
22 GroupBlock* b = new GroupBlock(parent);
27 void Graph::removeGroupBlock(GroupBlock *group) {
28 group->removeAllBlocks();
29 GroupBlock* parent = AB_TO_GRP(group->getParent());
30 parent->removeBlock(group);
31 groups.removeAll(group);
34 GroupBlock* Graph::getGroupBlockByName(QString name) {
35 foreach(GroupBlock* group, groups) {
36 if (group->getName() == name) return group;
41 FunctionalBlock* Graph::createFunctionalBlock(GroupBlock* group, ReferenceBlock* ref) {
43 FunctionalBlock* newBlock = new FunctionalBlock(group,ref);
45 group->addBlock(newBlock);
50 FunctionalBlock* Graph::duplicateFunctionalBlock(FunctionalBlock *block) {
52 ReferenceBlock* ref = block->getReference();
53 GroupBlock* group = AB_TO_GRP(block->getParent());
55 // adding to the graph
56 FunctionalBlock* newBlock = createFunctionalBlock(group,ref);
61 bool Graph::removeFunctionalBlock(FunctionalBlock* block) {
62 GroupBlock* group = AB_TO_GRP(block->getParent());
63 group->removeBlock(block);
67 FunctionalBlock* Graph::getFunctionalBlockByName(QString name, GroupBlock* parent) {
68 FunctionalBlock* block = NULL;
70 block = AB_TO_FUN(parent->getFunctionalBlockByName(name));
73 foreach(GroupBlock* group, groups) {
74 block = AB_TO_FUN(group->getFunctionalBlockByName(name));
75 if (block != NULL) return block;
81 FunctionalBlock* Graph::createSourceBlock(ReferenceBlock* ref) {
83 FunctionalBlock* newBlock = new FunctionalBlock(NULL,ref);
85 sources.append(newBlock);
89 FunctionalBlock* Graph::duplicateSourceBlock(FunctionalBlock *block) {
91 ReferenceBlock* ref = block->getReference();
93 // adding to the graph
94 FunctionalBlock* newBlock = createSourceBlock(ref);
98 FunctionalBlock* Graph::getSourceBlockByName(QString name) {
99 foreach(FunctionalBlock* block, sources) {
100 if (block->getName() == name) return block;
105 bool Graph::removeSourceBlock(FunctionalBlock *block) {
106 sources.removeAll(block);
110 void Graph::createPatterns() throw(Exception) {
112 foreach(AbstractBlock* block, sources) {
113 FunctionalBlock* funBlock = AB_TO_FUN(block);
115 funBlock->createPatterns();
122 foreach(AbstractBlock* block, groups) {
123 GroupBlock* group = AB_TO_GRP(block);
124 foreach(AbstractBlock* inBlock, group->getBlocks()) {
125 if (inBlock->isFunctionalBlock()) {
126 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
128 funBlock->createPatterns();
138 void Graph::resetPatternComputed() {
139 foreach(AbstractBlock* block, sources) {
140 block->setPatternComputed(false);
141 block->resetTraversalLevel();
143 foreach(AbstractBlock* block, groups) {
144 GroupBlock* group = AB_TO_GRP(block);
145 group->setPatternComputed(false);
146 block->resetTraversalLevel();
147 foreach(AbstractBlock* inBlock, group->getBlocks()) {
148 inBlock->setPatternComputed(false);
149 block->resetTraversalLevel();
154 void Graph::computeOutputPatterns(int nbExec) throw(Exception) {
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();