2 #include "GroupBlock.h"
3 #include "ReferenceBlock.h"
4 #include "FunctionalBlock.h"
5 #include "SpecialBlock.h"
16 void Graph::createTopGroup(bool createTopGroupIfaces) {
17 topGroup = new GroupBlock(this, NULL, createTopGroupIfaces);
18 topGroup->setName("top group");
19 groups.append(topGroup);
22 QList<AbstractInterface *> Graph::getOutsideInterfaces() {
23 return topGroup->getInterfaces();
26 GroupBlock* Graph::createChildGroupBlock(GroupBlock* parent, bool createGroupIface) {
27 GroupBlock* b = new GroupBlock(this, parent, createGroupIface);
32 void Graph::removeGroupBlock(GroupBlock *group) {
33 group->removeAllBlocks();
34 GroupBlock* parent = AB_TO_GRP(group->getParent());
35 parent->removeBlock(group);
36 groups.removeAll(group);
39 GroupBlock* Graph::getGroupBlockByName(QString name) {
40 foreach(GroupBlock* group, groups) {
41 if (group->getName() == name) return group;
46 FunctionalBlock* Graph::createFunctionalBlock(GroupBlock* group, ReferenceBlock* ref, bool createIfaces) {
48 FunctionalBlock* newBlock = NULL;
49 if (ref->getSpecialType() != -1) {
50 cout << "Graph: create special block from " << qPrintable(ref->getName()) << endl;
51 newBlock = new SpecialBlock(this, ref->getSpecialType(), group,ref, createIfaces);
54 cout << "Graph: create normal block from " << qPrintable(ref->getName()) << endl;
55 newBlock = new FunctionalBlock(this, group,ref, createIfaces);
57 group->addBlock(newBlock);
62 FunctionalBlock* Graph::duplicateFunctionalBlock(FunctionalBlock *block) {
64 ReferenceBlock* ref = block->getReference();
65 GroupBlock* group = AB_TO_GRP(block->getParent());
67 // adding to the graph
68 FunctionalBlock* newBlock = createFunctionalBlock(group,ref, true);
73 bool Graph::removeFunctionalBlock(FunctionalBlock* block) {
74 GroupBlock* group = AB_TO_GRP(block->getParent());
75 group->removeBlock(block);
79 FunctionalBlock* Graph::getFunctionalBlockByName(QString name, GroupBlock* parent) {
80 FunctionalBlock* block = NULL;
82 block = AB_TO_FUN(parent->getFunctionalBlockByName(name));
85 foreach(GroupBlock* group, groups) {
86 block = AB_TO_FUN(group->getFunctionalBlockByName(name));
87 if (block != NULL) return block;
93 FunctionalBlock* Graph::createStimuliBlock(ReferenceBlock* ref, bool createIfaces) {
94 /* A stimuli block is always a special block with idSpecial = 1 */
96 FunctionalBlock* newBlock = new SpecialBlock(this, AbstractBlock::Source, NULL,ref, createIfaces);
97 stimulis.append(newBlock);
101 FunctionalBlock* Graph::duplicateStimuliBlock(FunctionalBlock *block) {
103 ReferenceBlock* ref = block->getReference();
105 // adding to the graph
106 FunctionalBlock* newBlock = createStimuliBlock(ref, true);
110 FunctionalBlock* Graph::getStimuliBlockByName(QString name) {
111 foreach(FunctionalBlock* block, stimulis) {
112 if (block->getName() == name) return block;
117 bool Graph::removeStimuliBlock(FunctionalBlock *block) {
118 stimulis.removeAll(block);
122 void Graph::createPatterns() throw(Exception) {
124 foreach(AbstractBlock* block, stimulis) {
125 FunctionalBlock* funBlock = AB_TO_FUN(block);
127 funBlock->createPatterns();
134 foreach(AbstractBlock* block, groups) {
135 GroupBlock* group = AB_TO_GRP(block);
136 foreach(AbstractBlock* inBlock, group->getBlocks()) {
137 if (inBlock->isFunctionalBlock()) {
138 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
140 funBlock->createPatterns();
150 void Graph::resetPatternComputed() {
151 foreach(AbstractBlock* block, stimulis) {
152 block->setOutputPatternComputed(false);
153 block->resetTraversalLevel();
155 foreach(AbstractBlock* block, groups) {
156 GroupBlock* group = AB_TO_GRP(block);
157 group->setOutputPatternComputed(false);
158 block->resetTraversalLevel();
159 foreach(AbstractBlock* inBlock, group->getBlocks()) {
160 inBlock->setOutputPatternComputed(false);
161 block->resetTraversalLevel();
166 void Graph::computeOutputPatterns(int nbExec) throw(Exception) {
175 resetPatternComputed();
176 // search for all block that are source.
177 QList<FunctionalBlock*> sources;
178 sources.append(stimulis);
179 foreach(AbstractBlock* block, groups) {
180 GroupBlock* group = AB_TO_GRP(block);
181 foreach(AbstractBlock* inBlock, group->getBlocks()) {
182 FunctionalBlock* funBlock = AB_TO_FUN(inBlock);
183 if (inBlock->isSourceBlock()) {
184 sources.append(funBlock);
188 // search for maximum PP length
190 foreach(FunctionalBlock* block, sources) {
191 if (block->getProductionPatternLength() > maxPP) maxPP = block->getProductionPatternLength();
193 // compute output for generators
194 int maxExecLen = maxPP*nbExec;
195 foreach(FunctionalBlock* block, sources) {
196 int d = block->getProductionPatternLength();
197 block->computeOutputPattern((maxExecLen+d-1)/d);
199 // compute output for top group
201 topGroup->computeOutputPattern();
208 void Graph::generateVHDL(const QString &path) throw(Exception) {
210 topGroup->generateVHDL(path);
217 QList<QString> Graph::getExternalResources() {
218 QList<QString> list = topGroup->getExternalResources();