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 bool 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();
92 GroupBlock* group = AB_TO_GRP(block->getParent());
94 // adding to the graph
95 FunctionalBlock* newBlock = createSourceBlock(ref);
99 FunctionalBlock* Graph::getSourceBlockByName(QString name) {
100 foreach(FunctionalBlock* block, sources) {
101 if (block->getName() == name) return block;
106 bool Graph::removeSourceBlock(FunctionalBlock *block) {
107 sources.removeAll(block);
111 bool Graph::createPatterns() {
113 foreach(AbstractBlock* block, sources) {
114 FunctionalBlock* funBlock = AB_TO_FUN(block);
115 ok = funBlock->createPatterns();
116 if (!ok) return false;
119 foreach(AbstractBlock* block, groups) {
120 GroupBlock* group = AB_TO_GRP(block);
121 foreach(AbstractBlock* inBlock, group->getBlocks()) {
122 if (inBlock->isFunctionalBlock()) {
123 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
124 ok = funBlock->createPatterns();
125 if (!ok) return false;
132 void Graph::resetPatternComputed() {
133 foreach(AbstractBlock* block, sources) {
134 block->setPatternComputed(false);
136 foreach(AbstractBlock* block, groups) {
137 GroupBlock* group = AB_TO_GRP(block);
138 group->setPatternComputed(false);
139 foreach(AbstractBlock* inBlock, group->getBlocks()) {
140 inBlock->setPatternComputed(false);
145 bool Graph::computeOutputPatterns(int nbExec) {
148 resetPatternComputed();
149 // search for all block that are generators.
150 QList<FunctionalBlock*> generators;
151 generators.append(sources);
152 foreach(AbstractBlock* block, groups) {
153 GroupBlock* group = AB_TO_GRP(block);
154 foreach(AbstractBlock* inBlock, group->getBlocks()) {
155 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
156 if ((inBlock->isFunctionalBlock()) && (inBlock->isGeneratorBlock())) {
157 generators.append(funBlock);
161 // search for maximum delta
163 foreach(FunctionalBlock* block, generators) {
164 if (block->getDelta() > maxDelta) maxDelta = block->getDelta();
166 // compute output for generators
167 int maxExecLen = maxDelta*nbExec;
168 foreach(FunctionalBlock* block, generators) {
169 int d = block->getDelta();
170 block->computeOutputPattern((maxExecLen+d-1)/d);
172 // compute output for top group
173 topGroup->computeOutputPattern();