DynareMain2.cc 3.38 KB
Newer Older
1
/*
2
 * Copyright © 2008-2019 Dynare Team
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This file is part of Dynare.
 *
 * Dynare 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.
 *
 * Dynare 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 Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <iostream>

22 23
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
24
#include <boost/filesystem.hpp>
25
#pragma GCC diagnostic pop
26

27 28
#include "ParsingDriver.hh"
#include "ModFile.hh"
29
#include "ConfigFile.hh"
30
#include "ExtendedPreprocessorTypes.hh"
31 32

void
33
main2(stringstream &in, const string &basename, bool debug, bool clear_all, bool clear_global,
34
      bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console,
35
      bool nograph, bool nointeractive, bool parallel, const ConfigFile &config_file,
36
      WarningConsolidation &warnings, bool nostrict, bool stochastic, bool check_model_changes,
37
      bool minimal_workspace, bool compute_xrefs, FileOutputType output_mode,
38 39
      LanguageOutputType language, int params_derivs_order, bool transform_unary_ops,
      JsonOutputPointType json, JsonFileOutputType json_output_mode, bool onlyjson, bool jsonderivsimple,
40
      const string &mexext, const boost::filesystem::path &matlabroot,
41
      const boost::filesystem::path &dynareroot, bool onlymodel)
42
{
43
  ParsingDriver p(warnings, nostrict);
sebastien's avatar
sebastien committed
44

45 46
  boost::filesystem::remove_all(basename + "/model/json");

47
  // Do parsing and construct internal representation of mod file
Sébastien Villemot's avatar
Sébastien Villemot committed
48
  unique_ptr<ModFile> mod_file = p.parse(in, debug);
49
  if (json == JsonOutputPointType::parsing)
50
    mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
sebastien's avatar
sebastien committed
51

52
  // Run checking pass
53
  mod_file->checkPass(nostrict, stochastic);
54
  if (json == JsonOutputPointType::checkpass)
55
    mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
56

sebastien's avatar
sebastien committed
57
  // Perform transformations on the model (creation of auxiliary vars and equations)
58
  mod_file->transformPass(nostrict, stochastic, compute_xrefs || json == JsonOutputPointType::transformpass, transform_unary_ops);
59
  if (json == JsonOutputPointType::transformpass)
60
    mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson);
sebastien's avatar
sebastien committed
61

62
  // Evaluate parameters initialization, initval, endval and pounds
63
  mod_file->evalAllExpressions(warn_uninit);
64

65
  // Do computations
66
  mod_file->computingPass(no_tmp_terms, output_mode, params_derivs_order);
67
  if (json == JsonOutputPointType::computingpass)
68
    mod_file->writeJsonOutput(basename, json, json_output_mode, onlyjson, jsonderivsimple);
69 70

  // Write outputs
71
  if (output_mode != FileOutputType::none)
72
    mod_file->writeExternalFiles(basename, output_mode, language);
73
  else
74
    mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph,
75
                               nointeractive, config_file, check_model_changes, minimal_workspace, compute_xrefs,
76
                               mexext, matlabroot, dynareroot, onlymodel);
77

78
  cout << "Preprocessing completed." << endl;
79
}