Skip to content

Commit a517667

Browse files
committed
Correct waveform typing.
1 parent f570c26 commit a517667

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

compiler/signals/sigtyperules.cpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ using namespace std;
5050
// prototypes
5151
//--------------------------------------------------------------------------
5252

53-
static void setSigType(Tree sig, Type t);
53+
void setSigType(Tree sig, Type t);
5454
static Type getSigType(Tree sig);
5555
static TupletType* initialRecType(Tree t);
5656
static TupletType* maximalRecType(Tree t);
@@ -297,7 +297,7 @@ void typeAnnotation(Tree sig, bool causality)
297297
finished = true;
298298
for (int i = 0; i < n; i++) {
299299
newTuplet.clear();
300-
// cerr << i << "-" << *vrec[i] << ":" << *getSigType(vrec[i]) << " => " << *vtype[i] << endl;
300+
//cerr << i << "-" << *vrec[i] << ":" << *getSigType(vrec[i]) << " => " << *vtype[i] << endl;
301301
if (vtype[i] != getSigType(vrec[i])) {
302302
finished = false;
303303
newRecType = derefRecCert(vtype[i]);
@@ -373,7 +373,7 @@ ::Type getCertifiedSigType(Tree sig)
373373
* @param sig the signal we want to type
374374
* @param t the type of the signal
375375
*/
376-
static void setSigType(Tree sig, Type t)
376+
void setSigType(Tree sig, Type t)
377377
{
378378
TRACE(cerr << gGlobal->TABBER << "SET FIX TYPE OF " << ppsig(sig, MAX_ERROR_SIZE) << " TO TYPE " << *t << endl;)
379379
sig->setType(t);
@@ -564,12 +564,12 @@ static Type infereSigType(Tree sig, Tree env)
564564

565565
else if (isSigButton(sig)) {
566566
return castInterval(gGlobal->TGUI,
567-
gAlgebra.Button(interval(0,0))); // todo replace the name
567+
gAlgebra.Button(interval(0, 0))); // todo replace the name
568568
}
569569

570570
else if (isSigCheckbox(sig)) {
571571
return castInterval(gGlobal->TGUI,
572-
gAlgebra.Checkbox(interval(0,0))); // todo replace the name
572+
gAlgebra.Checkbox(interval(0, 0))); // todo replace the name
573573
}
574574

575575
else if (isSigVSlider(sig, label, cur, min, max, step)) {
@@ -578,7 +578,7 @@ static Type infereSigType(Tree sig, Tree env)
578578
Type t3 = T(max, env);
579579
Type t4 = T(step, env);
580580
return castInterval(gGlobal->TGUI,
581-
gAlgebra.VSlider(interval(0,0), // todo replace the name
581+
gAlgebra.VSlider(interval(0, 0), // todo replace the name
582582
t1->getInterval(),
583583
t2->getInterval(),
584584
t3->getInterval(),
@@ -591,7 +591,7 @@ static Type infereSigType(Tree sig, Tree env)
591591
Type t3 = T(max, env);
592592
Type t4 = T(step, env);
593593
return castInterval(gGlobal->TGUI,
594-
gAlgebra.HSlider(interval(0,0), // todo replace the name
594+
gAlgebra.HSlider(interval(0, 0), // todo replace the name
595595
t1->getInterval(),
596596
t2->getInterval(),
597597
t3->getInterval(),
@@ -604,7 +604,7 @@ static Type infereSigType(Tree sig, Tree env)
604604
Type t3 = T(max, env);
605605
Type t4 = T(step, env);
606606
return castInterval(gGlobal->TGUI,
607-
gAlgebra.NumEntry(interval(0,0), // todo replace the name
607+
gAlgebra.NumEntry(interval(0, 0), // todo replace the name
608608
t1->getInterval(),
609609
t2->getInterval(),
610610
t3->getInterval(),
@@ -649,7 +649,7 @@ static Type infereSigType(Tree sig, Tree env)
649649
Type tp = T(part, env);
650650
T(z, env);
651651
checkPartInterval(sig, tp);
652-
return makeSimpleType(kReal, kSamp, kExec, kVect, kNum, interval());
652+
return makeSimpleType(kReal, kSamp, kExec, kVect, kNum, interval(-1, 1));
653653
}
654654

655655
else if (isSigAttach(sig, s1, s2)) {
@@ -806,8 +806,8 @@ static Type infereWriteTableType(Type tbl, Type wi, Type ws)
806806
int v = wi->variability() | ws->variability();
807807
int c = wi->computability() | ws->computability();
808808
int vec = wi->vectorability() | ws->vectorability();
809-
interval i = reunion(ws->getInterval(), tbl->getInterval());
810-
809+
// Interval is the reunion of tbl (and its init signal) and ws
810+
interval i = reunion(tbl->getInterval(), ws->getInterval());
811811
TRACE(cerr << gGlobal->TABBER << "infering write table type : n="
812812
<< "NR"[n] << ", v="
813813
<< "KB?S"[v] << ", c="
@@ -954,31 +954,28 @@ static Type infereFVarType(Tree type)
954954
* - the waveform is known at compile time
955955
* - it can be vectorized because all values are known
956956
* - knum ???
957-
* - the interval is min and max of values
957+
* - the resulting interval is the reunion of all values intervals
958958
*/
959959
static Type infereWaveformType(Tree wfsig, Tree env)
960960
{
961-
bool iflag = isInt(wfsig->branch(0)->node());
961+
// start with the first item interval
962+
Tree v = wfsig->branch(0);
963+
bool iflag1 = isInt(v->node());
962964
int n = wfsig->arity();
963-
double lo, hi;
964-
965-
lo = hi = tree2float(wfsig->branch(0));
966-
T(wfsig->branch(0), env);
965+
interval res = (iflag1) ? gAlgebra.IntNum(tree2int(v)) : gAlgebra.FloatNum(tree2float(v));
966+
T(v, env);
967967

968+
// loop for remaining items
968969
for (int i = 1; i < n; i++) {
969-
Tree v = wfsig->branch(i);
970+
v = wfsig->branch(i);
970971
T(v, env);
971-
// compute range
972-
double f = tree2float(v);
973-
if (f < lo) {
974-
lo = f;
975-
} else if (f > hi) {
976-
hi = f;
977-
}
978-
iflag &= isInt(v->node());
972+
// compute interval
973+
bool iflag2 = isInt(v->node());
974+
res = reunion(res, iflag2 ? gAlgebra.IntNum(tree2int(v)) : gAlgebra.FloatNum(tree2float(v)));
975+
iflag1 &= iflag2;
979976
}
980977

981-
return makeSimpleType((iflag) ? kInt : kReal, kSamp, kComp, kScal, kNum, interval(lo, hi));
978+
return makeSimpleType((iflag1) ? kInt : kReal, kSamp, kComp, kScal, kNum, res);
982979
}
983980

984981
/**

0 commit comments

Comments
 (0)