2 #include "GroupBlock.h"
3 #include "ReferenceBlock.h"
4 #include "FunctionalBlock.h"
5 #include "SpecialBlock.h"
7 Graph::Graph(bool createTopGroupIface) {
8 topGroup = new GroupBlock(NULL, createTopGroupIface);
9 topGroup->setName("top group");
10 groups.append(topGroup);
18 QList<AbstractInterface *> Graph::getOutsideInterfaces() {
19 return topGroup->getInterfaces();
22 GroupBlock* Graph::createChildGroupBlock(GroupBlock* parent, bool createGroupIface) {
23 GroupBlock* b = new GroupBlock(parent, createGroupIface);
28 void 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, bool createIfaces) {
44 FunctionalBlock* newBlock = NULL;
45 if (ref->getSpecialType() != -1) {
46 newBlock = new SpecialBlock(ref->getSpecialType(), group,ref, createIfaces);
49 newBlock = new FunctionalBlock(group,ref, createIfaces);
51 group->addBlock(newBlock);
56 FunctionalBlock* Graph::duplicateFunctionalBlock(FunctionalBlock *block) {
58 ReferenceBlock* ref = block->getReference();
59 GroupBlock* group = AB_TO_GRP(block->getParent());
61 // adding to the graph
62 FunctionalBlock* newBlock = createFunctionalBlock(group,ref, true);
67 bool Graph::removeFunctionalBlock(FunctionalBlock* block) {
68 GroupBlock* group = AB_TO_GRP(block->getParent());
69 group->removeBlock(block);
73 FunctionalBlock* Graph::getFunctionalBlockByName(QString name, GroupBlock* parent) {
74 FunctionalBlock* block = NULL;
76 block = AB_TO_FUN(parent->getFunctionalBlockByName(name));
79 foreach(GroupBlock* group, groups) {
80 block = AB_TO_FUN(group->getFunctionalBlockByName(name));
81 if (block != NULL) return block;
87 FunctionalBlock* Graph::createStimuliBlock(ReferenceBlock* ref, bool createIfaces) {
88 /* A stimuli block is always a special block with idSpecial = 1 */
90 FunctionalBlock* newBlock = new SpecialBlock(AbstractBlock::Source, NULL,ref, createIfaces);
91 stimulis.append(newBlock);
95 FunctionalBlock* Graph::duplicateStimuliBlock(FunctionalBlock *block) {
97 ReferenceBlock* ref = block->getReference();
99 // adding to the graph
100 FunctionalBlock* newBlock = createStimuliBlock(ref, true);
104 FunctionalBlock* Graph::getStimuliBlockByName(QString name) {
105 foreach(FunctionalBlock* block, stimulis) {
106 if (block->getName() == name) return block;
111 bool Graph::removeStimuliBlock(FunctionalBlock *block) {
112 stimulis.removeAll(block);
116 void Graph::createPatterns() throw(Exception) {
118 foreach(AbstractBlock* block, stimulis) {
119 FunctionalBlock* funBlock = AB_TO_FUN(block);
121 funBlock->createPatterns();
128 foreach(AbstractBlock* block, groups) {
129 GroupBlock* group = AB_TO_GRP(block);
130 foreach(AbstractBlock* inBlock, group->getBlocks()) {
131 if (inBlock->isFunctionalBlock()) {
132 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
134 funBlock->createPatterns();
144 void Graph::resetPatternComputed() {
145 foreach(AbstractBlock* block, stimulis) {
146 block->setOutputPatternComputed(false);
147 block->resetTraversalLevel();
149 foreach(AbstractBlock* block, groups) {
150 GroupBlock* group = AB_TO_GRP(block);
151 group->setOutputPatternComputed(false);
152 block->resetTraversalLevel();
153 foreach(AbstractBlock* inBlock, group->getBlocks()) {
154 inBlock->setOutputPatternComputed(false);
155 block->resetTraversalLevel();
160 void Graph::computeOutputPatterns(int nbExec) throw(Exception) {
169 resetPatternComputed();
170 // search for all block that are source.
171 QList<FunctionalBlock*> sources;
172 sources.append(stimulis);
173 foreach(AbstractBlock* block, groups) {
174 GroupBlock* group = AB_TO_GRP(block);
175 foreach(AbstractBlock* inBlock, group->getBlocks()) {
176 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
177 if (inBlock->isSourceBlock()) {
178 sources.append(funBlock);
182 // search for maximum PP length
184 foreach(FunctionalBlock* block, sources) {
185 if (block->getProductionPatternLength() > maxPP) maxPP = block->getProductionPatternLength();
187 // compute output for generators
188 int maxExecLen = maxPP*nbExec;
189 foreach(FunctionalBlock* block, sources) {
190 int d = block->getProductionPatternLength();
191 block->computeOutputPattern((maxExecLen+d-1)/d);
193 // compute output for top group
195 topGroup->computeOutputPattern();
202 void Graph::generateVHDL(const QString &path) throw(Exception) {
204 topGroup->generateVHDL(path);
211 QList<QString> Graph::getExternalResources() {
212 QList<QString> list = topGroup->getExternalResources();