2 #include "GroupBlock.h"
3 #include "ReferenceBlock.h"
4 #include "FunctionalBlock.h"
6 Graph::Graph(bool createTopGroupIface) {
7 topGroup = new GroupBlock(NULL, createTopGroupIface);
8 topGroup->setName("top group");
9 groups.append(topGroup);
17 QList<AbstractInterface *> Graph::getOutsideInterfaces() {
18 return topGroup->getInterfaces();
21 GroupBlock* Graph::createChildGroupBlock(GroupBlock* parent, bool createGroupIface) {
22 GroupBlock* b = new GroupBlock(parent, createGroupIface);
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, bool createIfaces) {
43 FunctionalBlock* newBlock = new FunctionalBlock(group,ref, createIfaces);
44 group->addBlock(newBlock);
49 FunctionalBlock* Graph::duplicateFunctionalBlock(FunctionalBlock *block) {
51 ReferenceBlock* ref = block->getReference();
52 GroupBlock* group = AB_TO_GRP(block->getParent());
54 // adding to the graph
55 FunctionalBlock* newBlock = createFunctionalBlock(group,ref, true);
60 bool Graph::removeFunctionalBlock(FunctionalBlock* block) {
61 GroupBlock* group = AB_TO_GRP(block->getParent());
62 group->removeBlock(block);
66 FunctionalBlock* Graph::getFunctionalBlockByName(QString name, GroupBlock* parent) {
67 FunctionalBlock* block = NULL;
69 block = AB_TO_FUN(parent->getFunctionalBlockByName(name));
72 foreach(GroupBlock* group, groups) {
73 block = AB_TO_FUN(group->getFunctionalBlockByName(name));
74 if (block != NULL) return block;
80 FunctionalBlock* Graph::createSourceBlock(ReferenceBlock* ref, bool createIfaces) {
82 FunctionalBlock* newBlock = new FunctionalBlock(NULL,ref, createIfaces);
83 sources.append(newBlock);
87 FunctionalBlock* Graph::duplicateSourceBlock(FunctionalBlock *block) {
89 ReferenceBlock* ref = block->getReference();
91 // adding to the graph
92 FunctionalBlock* newBlock = createSourceBlock(ref, true);
96 FunctionalBlock* Graph::getSourceBlockByName(QString name) {
97 foreach(FunctionalBlock* block, sources) {
98 if (block->getName() == name) return block;
103 bool Graph::removeSourceBlock(FunctionalBlock *block) {
104 sources.removeAll(block);
108 void Graph::createPatterns() throw(Exception) {
110 foreach(AbstractBlock* block, sources) {
111 FunctionalBlock* funBlock = AB_TO_FUN(block);
113 funBlock->createPatterns();
120 foreach(AbstractBlock* block, groups) {
121 GroupBlock* group = AB_TO_GRP(block);
122 foreach(AbstractBlock* inBlock, group->getBlocks()) {
123 if (inBlock->isFunctionalBlock()) {
124 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
126 funBlock->createPatterns();
136 void Graph::resetPatternComputed() {
137 foreach(AbstractBlock* block, sources) {
138 block->setPatternComputed(false);
139 block->resetTraversalLevel();
141 foreach(AbstractBlock* block, groups) {
142 GroupBlock* group = AB_TO_GRP(block);
143 group->setPatternComputed(false);
144 block->resetTraversalLevel();
145 foreach(AbstractBlock* inBlock, group->getBlocks()) {
146 inBlock->setPatternComputed(false);
147 block->resetTraversalLevel();
152 void Graph::computeOutputPatterns(int nbExec) throw(Exception) {
161 resetPatternComputed();
162 // search for all block that are generators.
163 QList<FunctionalBlock*> generators;
164 generators.append(sources);
165 foreach(AbstractBlock* block, groups) {
166 GroupBlock* group = AB_TO_GRP(block);
167 foreach(AbstractBlock* inBlock, group->getBlocks()) {
168 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
169 if ((inBlock->isFunctionalBlock()) && (inBlock->isGeneratorBlock())) {
170 generators.append(funBlock);
174 // search for maximum PP length
176 foreach(FunctionalBlock* block, generators) {
177 if (block->getProductionPatternLength() > maxPP) maxPP = block->getProductionPatternLength();
179 // compute output for generators
180 int maxExecLen = maxPP*nbExec;
181 foreach(FunctionalBlock* block, generators) {
182 int d = block->getProductionPatternLength();
183 block->computeOutputPattern((maxExecLen+d-1)/d);
185 // compute output for top group
187 topGroup->computeOutputPattern();
194 void Graph::generateVHDL(const QString &path) throw(Exception) {
196 topGroup->generateVHDL(path);
203 QList<QString> Graph::getExternalResources() {
204 QList<QString> list = topGroup->getExternalResources();