[build] ozulis is no more linked to mugiwara
[ozulis.git] / src / main.cc
blob67434fb610b015873bb1e4f5a42cbe481dcc1934
1 #include <boost/program_options.hpp>
2 #include <boost/foreach.hpp>
3 #include <iostream>
4 #include <vector>
6 #include <core/assert.hh>
7 #include <compiler.hh>
8 #include <parse-task.hh>
10 namespace po = boost::program_options;
12 int
13 main(int argc, char **argv)
15 po::options_description desc("Help");
16 desc.add_options()
17 ("help,h", "produce help message")
18 ("out,o", "specify the output")
19 ("include-path,I", po::value< std::vector<std::string> >(), "include path")
20 ("input-file,i", po::value< std::vector<std::string> >(), "input sources")
21 ("ast-dump", "dump the AST at each pass")
22 ("ast-dump-parse", "dump the AST after the parsing")
23 ("ast-dump-type-check", "dump the AST after the type checking")
24 ("ast-dump-simplify", "dump the AST after the simplification");
26 po::positional_options_description pdesc;
27 pdesc.add("input-file", -1);
29 po::variables_map vm;
30 //po::store(po::parse_command_line(argc, argv, desc), vm);
31 po::store(po::command_line_parser(argc, argv).
32 options(desc).positional(pdesc).run(), vm);
33 po::notify(vm);
35 if (vm.count("help")) {
36 std::cout << desc << "\n";
37 return 0;
40 Compiler & compiler = Compiler::instance();
42 #define SET_OPT(Method, Opt) \
43 do { \
44 if (vm.count(Opt)) \
45 compiler.Method(true); \
46 } while (0)
48 /* compiler settings */
49 SET_OPT(enableAstDump, "ast-dump");
50 SET_OPT(enableAstDumpParse, "ast-dump-parse");
51 SET_OPT(enableAstDumpTypeCheck, "ast-dump-type-check");
52 SET_OPT(enableAstDumpSimplify, "ast-dump-simplify");
54 /* tasks */
55 if (vm.count("input-file"))
57 BOOST_FOREACH(const std::string & filename,
58 vm["input-file"].as< std::vector<std::string> >())
60 ParseTask * parseTask = new ParseTask();
61 parseTask->filename = filename;
62 compiler.addTask(parseTask);
66 compiler.compile();
67 return 0;