From be1e5da65c12cbecb07c0996103a3a4888371886 Mon Sep 17 00:00:00 2001 From: "joaquin.f.fernandez" Date: Fri, 21 Apr 2023 10:28:33 -0300 Subject: [PATCH] Check recursive deps in model definition. --- src/mmoc/ir/qss_model.cpp | 44 +++++++++++++++++++++++++-------------- src/mmoc/ir/qss_model.h | 16 +++++++------- 2 files changed, 35 insertions(+), 25 deletions(-) diff --git a/src/mmoc/ir/qss_model.cpp b/src/mmoc/ir/qss_model.cpp index 06505f66..c537cd27 100644 --- a/src/mmoc/ir/qss_model.cpp +++ b/src/mmoc/ir/qss_model.cpp @@ -40,14 +40,14 @@ namespace IR { QSSModelGenerator::QSSModelGenerator() : _qss_model_def(), _tabs(0), _post_process_eval(false) {} -void QSSModelGenerator::setup(EquationTable eqs) { _eqs = eqs; } +void QSSModelGenerator::setup(QSSModelConfig config) { _config = config; } void QSSModelGenerator::postProcess(SB::Deps::SetVertex vertex) { if (_post_process_eval) { return; } - EquationTable equations = _eqs; + EquationTable equations = _config.eqs; EquationTable::iterator it; std::stringstream simple; std::stringstream generic; @@ -77,10 +77,10 @@ void QSSModelGenerator::visitF(SB::Deps::SetVertex vertex, SB::Deps::VariableDep void QSSModelGenerator::visitG(SB::Deps::SetVertex v_vertex, SB::Deps::SetVertex g_vertex, SB::Deps::VariableDep var_dep, int index_shift) { if (var_dep.isRecursive()) { - Equation v_eq = getEquation(v_vertex, _eqs); - Equation g_eq = getEquation(g_vertex, _eqs); + Equation v_eq = getEquation(v_vertex, _config.eqs); + Equation g_eq = getEquation(g_vertex, _config.eqs); DefAlgDepsUse new_dep(g_eq, var_dep); - insertAlg(_der_deps, v_eq.id(), new_dep); + insertAlg(((v_eq.type() == IR::EQUATION::Algebraic) ? _alg_deps : _der_deps), v_eq.id(), new_dep); } } @@ -88,8 +88,8 @@ void QSSModelGenerator::visitG(SB::Deps::SetVertex v_vertex, SB::Deps::SetVertex SB::Deps::LMapExp use_map_exp, Expression use_exp, SB::PWLMap def_map, SB::Deps::LMapExp def_map_exp, SB::Set intersection) { - Equation v_eq = getEquation(v_vertex, _eqs); - Equation g_eq = getEquation(g_vertex, _eqs); + Equation v_eq = getEquation(v_vertex, _config.eqs); + Equation g_eq = getEquation(g_vertex, _config.eqs); DefAlgDepsUse new_dep(g_eq, def_map, use_exp, use_map_exp, def_map_exp, g_vertex.id()); insertAlg(((v_eq.type() == IR::EQUATION::Algebraic) ? _alg_deps : _der_deps), v_eq.id(), new_dep); } @@ -98,10 +98,12 @@ void QSSModelGenerator::initG(SB::Deps::SetVertex vertex, SB::Deps::SetEdge edge QSSModelDef QSSModelGenerator::def() { return _qss_model_def; } -template -QSSModel::QSSModel() {} +template +QSSModel::QSSModel() +{ +} -template +template void QSSModel::build(EquationTable eqs) { EquationTable algebraics = ModelConfig::instance().algebraics(); @@ -109,16 +111,26 @@ void QSSModel::build(EquationTable eqs) QSSModelBuilder qss_model; IndexShiftBuilder index_shifts(algebraics); GraphBuilder EQSBGraph(eqs, algebraics); - qss_model.setup(eqs); - qss_model.compute(EQSBGraph.build(), index_shifts.build()); + SB::Deps::Graph graph = EQSBGraph.build(); + QSSModelConfig config; + config.eqs = eqs; + config.graph = graph; + qss_model.setup(config); + qss_model.compute(graph, index_shifts.build()); _qss_model_def = qss_model.def(); } -template -string QSSModel::simpleDef() { return _qss_model_def.simple; } +template +string QSSModel::simpleDef() +{ + return _qss_model_def.simple; +} -template -string QSSModel::genericDef() { return _qss_model_def.generic; } +template +string QSSModel::genericDef() +{ + return _qss_model_def.generic; +} template class QSSModel; diff --git a/src/mmoc/ir/qss_model.h b/src/mmoc/ir/qss_model.h index e9f85fdb..815ac3f3 100644 --- a/src/mmoc/ir/qss_model.h +++ b/src/mmoc/ir/qss_model.h @@ -37,7 +37,6 @@ struct QSSModelDef { std::string generic; }; - class QSSModelGenerator { public: QSSModelGenerator(); @@ -48,14 +47,14 @@ class QSSModelGenerator { void postProcess(SB::Deps::SetVertex vertex); void visitF(SB::Deps::SetVertex vertex, SB::Deps::VariableDep var_dep); void visitF(SB::Deps::SetVertex vertex, SB::Deps::VariableDep var_dep, SB::Deps::SetVertex gen_vertex); - void visitG(SB::Deps::SetVertex v_vertex, SB::Deps::SetVertex g_vertex, SB::Deps::VariableDep var_dep, int index_shift); - void visitG(SB::Deps::SetVertex v_vertex, SB::Deps::SetVertex g_vertex, SB::PWLMap use_map, SB::Deps::LMapExp use_map_exp, Expression use_exp, SB::PWLMap def_map, - SB::Deps::LMapExp def_map_exp, SB::Set intersection); + void visitG(SB::Deps::SetVertex v_vertex, SB::Deps::SetVertex g_vertex, SB::Deps::VariableDep var_dep, int index_shift = 0); + void visitG(SB::Deps::SetVertex v_vertex, SB::Deps::SetVertex g_vertex, SB::PWLMap use_map, SB::Deps::LMapExp use_map_exp, + Expression use_exp, SB::PWLMap def_map, SB::Deps::LMapExp def_map_exp, SB::Set intersection); void initG(SB::Deps::SetVertex vertex, SB::Deps::SetEdge edge); QSSModelDef def(); - void setup(EquationTable eqs); - EquationTable config() { return EquationTable(); } + void setup(QSSModelConfig config); + QSSModelConfig config() { return _config; } protected: QSSModelDef _qss_model_def; @@ -63,10 +62,10 @@ class QSSModelGenerator { AlgDepsMap _der_deps; AlgDepsMap _alg_deps; bool _post_process_eval; - EquationTable _eqs; + QSSModelConfig _config; }; -template +template class QSSModel { public: QSSModel(); @@ -88,6 +87,5 @@ typedef QSSModel ZCModelGen; typedef QSSModel OutputModelGen; - } // namespace IR } // namespace MicroModelica