3 #include "recursivness.hh"
4 #include "occurences.hh"
6 #include "sigtyperules.hh"
12 * Extended Variability with recursiveness indication
14 static int xVariability (int v
, int r
)
16 //cerr << "xVariability (" << v << ", " << r << ")" << endl;
17 //assert (v < 3); // kKonst=0, kBlock=1, kSamp=2
18 //assert(r==0 | v==2);
23 //-------------------------------------------------
25 //-------------------------------------------------
27 Occurences::Occurences(int v
, int r
) : fXVariability(xVariability(v
,r
)) {
28 for (int i
=0; i
<4; i
++) fOccurences
[i
]=0;
34 Occurences
* Occurences::incOccurences(int v
, int r
, int d
) {
35 int ctxt
= xVariability(v
,r
);
36 //assert (ctxt >= fXVariability);
37 fOccurences
[ctxt
] += 1;
38 fMultiOcc
= fMultiOcc
| (ctxt
> fXVariability
) | (fOccurences
[ctxt
] > 1);
40 //cerr << "Occurence outside a delay " << endl;
44 //cerr << "Max delay : " << fMaxDelay << " <- " << d << endl;
50 bool Occurences::hasMultiOccurences() const { return fMultiOcc
; }
52 bool Occurences::hasOutDelayOccurences() const { return fOutDelayOcc
; }
54 int Occurences::getMaxDelay() const
59 //--------------------------------------------------
60 // Mark and retrieve occurences of subtrees of root
61 //--------------------------------------------------
63 void OccMarkup::mark(Tree root
)
66 fPropKey
= tree(unique("OCCURENCES"));
69 while (isList(root
)) {
70 //incOcc(kSamp, 1, hd(root));
71 incOcc(nil
, kSamp
, 0, 0, hd(root
));
74 //cerr << "END OF LIST IS " << *root << endl;
76 //incOcc(kSamp, 1, root);
77 incOcc(nil
, kSamp
, 0, 0, root
);
81 Occurences
* OccMarkup::retrieve(Tree t
)
83 Occurences
* p
= getOcc(t
);
85 //cerr << "No Occurences info attached to : " << *t << endl;
91 //------------------------------------------------------------------------------
92 // Increment the occurences of t within context v,r,d and proceed recursively
93 //------------------------------------------------------------------------------
95 void OccMarkup::incOcc(Tree env
, int v
, int r
, int d
, Tree t
)
97 // Check if we have already visited this tree
98 Occurences
* occ
= getOcc(t
);
101 // 1) We build initial occurence information
102 Type ty
= getCertifiedSigType(t
);
103 int v0
= ty
->variability();
104 int r0
= getRecursivness(t
);
106 occ
= new Occurences(v0
,r0
);
109 // We mark the subtrees of t
111 if (isSigFixDelay(t
,x
,y
)) {
112 Type g2
= getCertifiedSigType(y
);
113 int d2
= checkDelayInterval(g2
);
115 incOcc(env
, v0
, r0
, d2
, x
);
116 incOcc(env
, v0
, r0
, 0, y
);
117 } else if (isSigPrefix(t
,y
,x
)) {
118 incOcc(env
, v0
, r0
, 1, x
);
119 incOcc(env
, v0
, r0
, 0, y
);
120 } else if (isSigSelect3(t
,c
,y
,x
,z
)) {
121 // make a special case for select3 implemented with real if
122 // because the c expression will be used twice in the C++
124 incOcc(env
, v0
, r0
, 0, c
);
125 incOcc(env
, v0
, r0
, 0, c
);
126 incOcc(env
, v0
, r0
, 0, x
);
127 incOcc(env
, v0
, r0
, 0, y
);
128 incOcc(env
, v0
, r0
, 0, z
);
131 int n
= getSubSignals(t
, br
);
132 if (n
>0 && ! isSigGen(t
)) {
133 for (int i
=0; i
<n
; i
++) incOcc(env
, v0
, r0
, 0, br
[i
]);
138 occ
->incOccurences(v
,r
,d
);
144 Occurences
* OccMarkup::getOcc(Tree t
)
146 Tree p
= t
->getProperty(fPropKey
);
148 return (Occurences
*) tree2ptr(p
);
155 void OccMarkup::setOcc(Tree t
, Occurences
* occ
)
157 t
->setProperty(fPropKey
, tree(occ
));
163 * return the position of a signal in the current recursive environment
164 * @param env the current recursive environment of the signal
165 * @param t signal we want to know the position
166 * @return the position in the recursive environment
168 static int position (Tree env
, Tree t
, int p
)
170 if (isNil(env
)) return 0; // was not in the environment
171 if (hd(env
) == t
) return p
;
172 else return position (tl(env
), t
, p
+1);