this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
3/*
4 * Main authors:
5 * Guido Tack <guido.tack@monash.edu>
6 * Gleb Belov <gleb.belov@monash.edu>
7 */
8
9/* This Source Code Form is subject to the terms of the Mozilla Public
10 * License, v. 2.0. If a copy of the MPL was not distributed with this
11 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
12
13/* This (main) file coordinates flattening and solving.
14 * The corresponding modules are flexibly plugged in
15 * as derived classes, prospectively from DLLs.
16 * A flattening module should provide MinZinc::GetFlattener()
17 * A solving module should provide an object of a class derived from SolverFactory.
18 * Need to get more flexible for multi-pass & multi-solving stuff TODO
19 */
20
21#include <minizinc/astexception.hh>
22#include <minizinc/codegen.hh>
23#include <minizinc/prettyprinter.hh>
24#include <minizinc/reader.hh>
25#include <minizinc/timer.hh>
26#include <minizinc/typecheck.hh>
27
28#include <chrono>
29#include <cstdlib>
30#include <ctime>
31#include <fstream>
32#include <iomanip>
33#include <iostream>
34#include <ratio>
35
36using namespace std;
37using namespace MiniZinc;
38
39int main(int argc, const char** argv) {
40 Timer starttime;
41 GCLock lock;
42 try {
43 MznReader r(std::cout, std::cerr);
44 Model* m(nullptr);
45 try {
46 /*
47 std::vector<std::string> args(argc-1);
48 for (int i=1; i<argc; i++)
49 args[i-1] = argv[i];
50 fSuccess = (slv.run(args,"",argv[0]) != SolverInstance::ERROR);
51 */
52 std::vector<std::string> args(argc - 1);
53 for (int i = 1; i < argc; i++) args[i - 1] = argv[i];
54 switch (r.processOptions(args)) {
55 case MznReader::OPTION_FINISH:
56 return 0;
57 case MznReader::OPTION_ERROR:
58 return 1;
59 default:
60 break;
61 }
62
63 Model* m(r.read());
64
65 Env env(m, std::cout, std::cerr);
66 std::vector<TypeError> typeErrors;
67 typecheck(env, m, typeErrors, true /* ignoreUndefinedParameters */,
68 false /* allowMultiAssignment */, false /* isFlatZinc */);
69 // debugprint(m);
70 m = env.envi().model;
71
72 CodeGen cg;
73 CG::run(cg, m);
74 } catch (const LocationException& e) {
75 if (r.get_flag_verbose()) std::cerr << std::endl;
76 std::cerr << e.loc() << ":" << std::endl;
77 std::cerr << e.what() << ": " << e.msg() << std::endl;
78 } catch (const Exception& e) {
79 if (r.get_flag_verbose()) std::cerr << std::endl;
80 std::string what = e.what();
81 std::cerr << what << (what.empty() ? "" : ": ") << e.msg() << std::endl;
82 } catch (const exception& e) {
83 if (r.get_flag_verbose()) std::cerr << std::endl;
84 std::cerr << e.what() << std::endl;
85 } catch (...) {
86 if (r.get_flag_verbose()) std::cerr << std::endl;
87 std::cerr << " UNKNOWN EXCEPTION." << std::endl;
88 }
89
90 if (r.get_flag_verbose()) {
91 std::cerr << " Done (";
92 cerr << "overall time " << starttime.stoptime() << ")." << std::endl;
93 }
94 } catch (const Exception& e) {
95 std::string what = e.what();
96 std::cerr << what << (what.empty() ? "" : ": ") << e.msg() << std::endl;
97 std::exit(EXIT_FAILURE);
98 }
99 return 0;
100} // int main()