-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
96 lines (81 loc) · 2.88 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*****************************************************************************
This file is part of Modelica C Compiler.
Modelica C Compiler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Modelica C Compiler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Modelica C Compiler. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#include <cstdlib>
#include <stdio.h>
#include <iostream>
#include <unistd.h>
#include <parser/parse.h>
#include <util/debug.h>
#include <mmo/mmo_class.h>
#include <ast/class.h>
#include <util/symbol_table.h>
#include <causalize/causalization_strategy.h>
#include <causalize/causalize2/graph_builder.h>
#include <causalize/causalize2/graph_printer.h>
#include <causalize/causalize2/causalization_algorithm.h>
int main(int argc, char** argv){
int opt;
int r;
AST_Class modelica_class;
while((opt = getopt(argc, argv, "d:")) != -1){
switch(opt){
case 'd':
if(optarg != NULL && isDebugParam(optarg)){
debugInit(optarg);
}else{
ERROR("Command line option d requires an argument\n");
}
break;
}
}
if(optind < argc){
modelica_class = parseClass(argv[optind],&r);
}else{
/* si no se especifico un archivo leo de stdin*/
modelica_class = parseClass("", &r);
}
if(r!=0){
return -1;
}
/* creamos la clase MicroModelica */
TypeSymbolTable ty = newTypeSymbolTable();
MMO_Class mmo_class = newMMO_Class(modelica_class, ty);
ReducedGraphBuilder *gb = new ReducedGraphBuilder(mmo_class);
CausalizationGraph g = gb->makeGraph();
//para debuggeo: crea archivo grafo.dot
if(debugIsEnabled('g')){
GraphPrinter gp(g);
gp.printGraph();
}
CausalizationStrategy2 *cs = new CausalizationStrategy2(g);
if(cs->causalize()){
if(debugIsEnabled('c')){
cout << "Result of causalization (variable, [range,] equationID):" << endl;
cs->print();
}
}else{
//si no anduvo, probamos con la estrategia clasica
DEBUG('c', "Executing the classic strategy\n");
CausalizationStrategy *cs_clasica = new CausalizationStrategy(mmo_class);
AST_ClassList cl = newAST_ClassList();
cs_clasica->causalize(mmo_class->name(), cl);
DEBUG('c', "Causalized Equations:\n");
MMO_EquationList causalEqs = mmo_class->getEquations();
MMO_EquationListIterator causalEqsIter;
foreach(causalEqsIter, causalEqs) {
DEBUG('c', "%s", current_element(causalEqsIter)->print().c_str());
}
}
return 0;
}