Skip to content

Commit 2447429

Browse files
[iss-325]
Squashed commit of the following: commit a861df4 Author: joaquin.f.fernandez <joaquin.f.fernandez@gmail.com> Date: Mon Jun 29 10:33:56 2026 -0300 Extend compilation logs. commit db77a27 Author: joaquin.f.fernandez <joaquin.f.fernandez@gmail.com> Date: Mon Jun 29 10:33:24 2026 -0300 Adapt expression visitors. commit 1622a58 Author: joaquin.f.fernandez <joaquin.f.fernandez@gmail.com> Date: Mon Jun 29 10:31:51 2026 -0300 Allow negative slopes in linear maps.
1 parent aba0cba commit 2447429

6 files changed

Lines changed: 26 additions & 10 deletions

File tree

src/mmoc/deps/sbg_graph/build_from_exps.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ EdgeMaps generatePWLMaps(Expression exp, Set dom, Set unk_dom, int offset, strin
398398
LOG << "Init: " << range_init_value << endl;
399399
int map_first_value = pwl_map_values.constant() + pwl_map_values.slope() * range_init_value + set_vertex_init;
400400
LOG << "Map first: " << map_first_value << endl;
401+
LOG << "Constant: " << pwl_map_values.constant() << endl;
402+
LOG << "Slope: " << pwl_map_values.slope() << endl;
403+
LOG << "Range init value: " << range_init_value << endl;
404+
LOG << "Set vertex init: " << set_vertex_init << endl;
405+
LOG << "Set vertex offset: " << set_vertex_offset << endl;
401406
constant_pwl_map_u_it = constant_pwl_map_u.insert(constant_pwl_map_u_it, map_first_value - set_vertex_offset);
402407
slope_pwl_map_u_it = slope_pwl_map_u.insert(slope_pwl_map_u_it, pwl_map_values.slope());
403408
exp_constants.insert(pwl_map_values.constant());

src/mmoc/deps/sbg_graph/linear_map.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ struct LMapImp {
3838
negative = true;
3939
}
4040
}
41-
if (!negative) {
4241
if (slopes.size() == constants.size()) {
4342
_slopes = slopes;
4443
_constants = constants;
4544
_dims = slopes.size();
4645
}
47-
}
4846
}
4947

5048
// Constructs the id of LMaps

src/mmoc/util/visitors/eval_init_exp.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class EvalInitExp : public AST_Expression_Fold<int> {
3333
int foldTraverseElement(AST_Expression exp);
3434
int foldTraverseElement(int l, int r, BinOpType bot);
3535
int foldTraverseElementUMinus(AST_Expression exp);
36+
int _u_minus;
3637
};
3738

3839
} // namespace Util

src/mmoc/util/visitors/parse_index.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace MicroModelica {
2828
using namespace IR;
2929
namespace Util {
3030

31-
ParseIndex::ParseIndex() : _constant(0), _factor(1), _variable() {}
31+
ParseIndex::ParseIndex() : _constant(0), _factor(1), _variable(), _u_minus(1), _minus_sign(1) {}
3232

3333
int ParseIndex::constant() { return _constant; }
3434

@@ -57,6 +57,7 @@ AST_Expression ParseIndex::foldTraverseElement(AST_Expression exp)
5757
}
5858
} else {
5959
_variable = cr->name();
60+
_factor *= _u_minus;
6061
}
6162
break;
6263
}
@@ -67,24 +68,33 @@ AST_Expression ParseIndex::foldTraverseElement(AST_Expression exp)
6768
foreach (it, outputs) {
6869
apply(current_element(it));
6970
}
71+
break;
7072
}
7173
case EXPINTEGER:
7274
_constant = exp->getAsInteger()->val();
75+
break;
7376
default:
7477
break;
7578
}
7679
return exp;
7780
}
7881

79-
// @TODO: review if this is needed.
80-
AST_Expression ParseIndex::foldTraverseElementUMinus(AST_Expression exp) { return apply(exp->getAsUMinus()->exp()); }
82+
AST_Expression ParseIndex::foldTraverseElementUMinus(AST_Expression exp)
83+
{
84+
_u_minus = -1;
85+
AST_Expression ret = newAST_Expression_UnaryMinus(apply(exp->getAsUMinus()->exp()));
86+
_u_minus = 1;
87+
return ret;
88+
}
8189

8290
int ParseIndex::getConstant(AST_Expression left, AST_Expression right)
8391
{
8492
if (left->expressionType() == EXPINTEGER) {
93+
_minus_sign = 1;
8594
return left->getAsInteger()->val();
8695
}
8796
if (right->expressionType() == EXPINTEGER) {
97+
_minus_sign = -1;
8898
return right->getAsInteger()->val();
8999
}
90100
assert(false);
@@ -95,13 +105,14 @@ AST_Expression ParseIndex::foldTraverseElement(AST_Expression l, AST_Expression
95105
{
96106
switch (bot) {
97107
case BINOPADD:
98-
_constant = getConstant(l, r);
108+
_constant = _u_minus * getConstant(l, r);
99109
break;
100110
case BINOPSUB:
101-
_constant = -1 * getConstant(l, r);
111+
_constant = _u_minus * _minus_sign * getConstant(l, r);
112+
_factor = _minus_sign * -1;
102113
break;
103114
case BINOPMULT:
104-
_factor = getConstant(l, r);
115+
_factor = _u_minus * getConstant(l, r);
105116
break;
106117
default:
107118
break;

src/mmoc/util/visitors/parse_index.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class ParseIndex : public AST_Expression_Visitor<AST_Expression> {
4646
int _constant;
4747
int _factor;
4848
std::string _variable;
49+
int _u_minus;
50+
int _minus_sign;
4951
};
5052

5153
} // namespace Util

src/mmoc/util/visitors/partial_eval_exp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ AST_Expression PartialEvalExp::foldTraverseElement(AST_Expression exp)
7878

7979
AST_Expression PartialEvalExp::foldTraverseElementUMinus(AST_Expression exp)
8080
{
81-
AST_Expression_Integer zero = (AST_Expression_Integer)newAST_Expression_Integer(0);
82-
return (foldTraverseElement(zero, apply(exp->getAsUMinus()->exp()), BINOPSUB));
81+
return newAST_Expression_UnaryMinus(apply(exp->getAsUMinus()->exp()));
8382
}
8483

8584
AST_Expression PartialEvalExp::foldTraverseElement(AST_Expression left, AST_Expression right, BinOpType binOpType)

0 commit comments

Comments
 (0)