Skip to content

Commit 7449f99

Browse files
committed
Fix boxPropagateSig when called from eval.cpp
1 parent 7d86985 commit 7449f99

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

compiler/evaluate/eval.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static Tree realeval(Tree exp, Tree visited, Tree localValEnv)
364364
int n, m;
365365
getBoxType(re, &n, &m);
366366

367-
Tree lres = boxPropagateSig(gGlobal->nil, a2, lsig);
367+
Tree lres = boxPropagateSig(gGlobal->nil, a2, lsig, true);
368368
if (isList(lres) && isNil(tl(lres))) {
369369
Tree r = simplify(hd(lres));
370370
if (isNum(r)) { return r; }
@@ -630,9 +630,9 @@ static Tree realeval(Tree exp, Tree visited, Tree localValEnv)
630630

631631
if ((i1 == 0) & (o1 == 1) & (i2 == 0) & (o2 == 1) & (i3 == 0) & (o3 > 1) & ((o3 % 2) == 0)) {
632632
// We are in good shape
633-
Tree ls1 = boxPropagateSig(gGlobal->nil, v1, makeSigInputList(0));
634-
Tree ls2 = boxPropagateSig(gGlobal->nil, v2, makeSigInputList(0));
635-
Tree lsr = boxPropagateSig(gGlobal->nil, vr, makeSigInputList(0));
633+
Tree ls1 = boxPropagateSig(gGlobal->nil, v1, makeSigInputList(0), true);
634+
Tree ls2 = boxPropagateSig(gGlobal->nil, v2, makeSigInputList(0), true);
635+
Tree lsr = boxPropagateSig(gGlobal->nil, vr, makeSigInputList(0), true);
636636

637637
// All these lists should be list of constant numerical signals
638638
// that we need to convert back to box expressions
@@ -767,7 +767,7 @@ static bool isBoxNumeric(Tree in, Tree& out)
767767
v = a2sb(in);
768768
if (getBoxType(v, &numInputs, &numOutputs) && (numInputs == 0) && (numOutputs == 1)) {
769769
// Potential numerical expression
770-
Tree lsignals = boxPropagateSig(gGlobal->nil, v, makeSigInputList(numInputs));
770+
Tree lsignals = boxPropagateSig(gGlobal->nil, v, makeSigInputList(numInputs), true);
771771
Tree res = simplify(hd(lsignals));
772772
if (isSigReal(res, &x)) {
773773
out = boxReal(x);
@@ -819,7 +819,7 @@ static double eval2double(Tree exp, Tree visited, Tree localValEnv)
819819
// Never reached since evalerror throws an exception
820820
return 1;
821821
} else {
822-
Tree lsignals = boxPropagateSig(gGlobal->nil, diagram, makeSigInputList(numInputs));
822+
Tree lsignals = boxPropagateSig(gGlobal->nil, diagram, makeSigInputList(numInputs), true);
823823
Tree val = simplify(hd(lsignals));
824824
return tree2double(val);
825825
}
@@ -848,7 +848,7 @@ static int eval2int(Tree exp, Tree visited, Tree localValEnv)
848848
// Never reached since evalerror throws an exception
849849
return 1;
850850
} else {
851-
Tree lsignals = boxPropagateSig(gGlobal->nil, diagram, makeSigInputList(numInputs));
851+
Tree lsignals = boxPropagateSig(gGlobal->nil, diagram, makeSigInputList(numInputs), true);
852852
Tree val = simplify(hd(lsignals));
853853
return tree2int(val);
854854
}
@@ -1519,7 +1519,7 @@ static Tree numericBoxSimplification(Tree box)
15191519
// Propagate signals to discover if it simplifies to a number
15201520
int i1;
15211521
double x1;
1522-
Tree lsignals = boxPropagateSig(gGlobal->nil, box, makeSigInputList(0));
1522+
Tree lsignals = boxPropagateSig(gGlobal->nil, box, makeSigInputList(0), true);
15231523
Tree s = simplify(hd(lsignals));
15241524

15251525
if (isSigReal(s, &x1)) {

compiler/propagate/propagate.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,17 @@ siglist makeSigInputList(int n)
670670
* @return the resulting list of output signals
671671
*/
672672

673-
Tree boxPropagateSig(Tree path, Tree box, const siglist& lsig)
673+
Tree boxPropagateSig(Tree path, Tree box, const siglist& lsig, bool inEval)
674674
{
675675
bool fakeTap = true;
676676
siglistAndTaps withFakeTaps = propagate(gGlobal->nil, path, box, lsig, fakeTap);
677+
678+
// In eval.cpp, we call this function to simplify some boxes. In that case we don't care
679+
// about extra taps, just return the signals without any further processing.
680+
if (inEval) {
681+
return listConvert(withFakeTaps.first);
682+
}
683+
677684
int ins, outs;
678685
getBoxType(box, &ins, &outs);
679686

compiler/propagate/propagate.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ siglist makeSigInputList(int n);
3838
* compute the list of outputs of a block-diagram with n inputs, do:
3939
* Tree lsig = boxPropagateSig(path, box, makeSigInputList(n));
4040
*/
41-
Tree boxPropagateSig(Tree path, Tree box, const siglist& lsig);
41+
Tree boxPropagateSig(Tree path, Tree box, const siglist& lsig, bool inEval=false);
4242

4343
/**
4444
* Propagate a list of signals into a block diagram. Do memoization.

0 commit comments

Comments
 (0)