summaryrefslogtreecommitdiff
path: root/tiger-compiler/src/tc.cc
blob: 0453714081f1001dc380e850d89b1407a190a09a (plain)
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
/**
 ** \file tc.cc
 ** \brief The compiler driver.
 */

#include <cstdlib>
#include <exception>
#include <iostream>
#include <stdexcept>
#include <common.hh>

#include <task/task-register.hh>

int main(int argc, char** argv)
{
  program_name = argv[0];

  try
    {
      task_timer.start();
      task_timer.push("rest");

      filename = task::TaskRegister::instance().parse_arg(argc, argv);
      task_error().exit_on_error();

      // If `help', `usage' or `version' is called, just exit.
      if (filename == nullptr)
        return 0;

      if (task::TaskRegister::instance().nb_of_task_to_execute_get() == 0)
        task::TaskRegister::instance().enable_task("parse");

      task::TaskRegister::instance().execute();
      task_timer << task::TaskRegister::instance().timer_get();
      task_error().exit_on_error();
    }

  // Required to enable stack unwinding.
  catch (const std::invalid_argument& e)
    {
      return 64;
    }
  catch (const std::runtime_error& e)
    {
      if (e.what() != std::string(""))
        std::cerr << e.what() << '\n';
    }
  catch (const misc::error& e)
    {
      std::cerr << e;
      return e.status_get_value();
    }
}