[visitors] ported llvm asm generator
[ozulis.git] / src / ozulis / main.cc
blobd45ba6fe5bf6c88d29bb30b8673b8d7a9632b923
1 #include <boost/program_options.hpp>
2 #include <boost/foreach.hpp>
3 #include <iostream>
4 #include <vector>
6 #include <ozulis/core/assert.hh>
7 #include <ozulis/compiler.hh>
8 #include <ozulis/parse-task.hh>
10 namespace po = boost::program_options;
11 using namespace ozulis;
13 int
14 main(int argc, char **argv)
16 po::options_description desc("Help");
17 desc.add_options()
18 ("help,h", "produce help message")
19 ("out,o", "specify the output")
20 ("include-path,I", po::value< std::vector<std::string> >(), "include path")
21 ("input-file,i", po::value< std::vector<std::string> >(), "input sources")
22 ("ast-dump", "dump the AST at each pass")
23 ("ast-dump-parse", "dump the AST after the parsing")
24 ("ast-dump-type-check", "dump the AST after the type checking")
25 ("ast-dump-simplify", "dump the AST after the simplification");
27 po::positional_options_description pdesc;
28 pdesc.add("input-file", -1);
30 po::variables_map vm;
31 //po::store(po::parse_command_line(argc, argv, desc), vm);
32 po::store(po::command_line_parser(argc, argv).
33 options(desc).positional(pdesc).run(), vm);
34 po::notify(vm);
36 if (vm.count("help")) {
37 std::cout << desc << "\n";
38 return 0;
41 Compiler & compiler = Compiler::instance();
43 #define SET_OPT(Method, Opt) \
44 do { \
45 if (vm.count(Opt)) \
46 compiler.Method(true); \
47 } while (0)
49 /* compiler settings */
50 SET_OPT(enableAstDump, "ast-dump");
51 SET_OPT(enableAstDumpParse, "ast-dump-parse");
52 SET_OPT(enableAstDumpTypeCheck, "ast-dump-type-check");
53 SET_OPT(enableAstDumpSimplify, "ast-dump-simplify");
55 /* tasks */
56 if (vm.count("input-file"))
58 BOOST_FOREACH(const std::string & filename,
59 vm["input-file"].as< std::vector<std::string> >())
61 ParseTask * parseTask = new ParseTask();
62 parseTask->filename = filename;
63 compiler.addTask(parseTask);
67 compiler.compile();
68 return 0;