-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
34 lines (28 loc) · 1.3 KB
/
Copy pathmain.cpp
File metadata and controls
34 lines (28 loc) · 1.3 KB
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
#include <iostream>
#include "CLI11.hpp"
#include "CodeGen.h"
int main(int argc, char** argv) {
CLI::App app{"ZiYue4D Compiler"};
// Define options
std::string input, output, std;
bool show_progress = false;
CLI::Option* option_input = app.add_option("-i,--input", input, "Input source file")->check(CLI::ExistingFile)->
required(true);
CLI::Option* option_output = app.add_option("-o,--output", output, "Output source file")->required(false);
CLI::Option* option_stdlib = app.add_option("-s,--std", std, "Standard header")->check(CLI::ExistingFile)->required(false)->
default_val("std.sb");
CLI::Option* option_progress = app.add_flag("-p,--progress", show_progress, "Show progress")->required(false);
CLI11_PARSE(app, argc, argv);
if (show_progress) std::cout << "Compiling...\n";
AST ast(std::make_unique<Lex>(input));
if (ast.parse()) return 1;
if (show_progress) std::cout << "Analyzing...\n";
SemanticAnalyzer analyzer(std::make_unique<AST>(std::move(ast)), std);
if (analyzer.analyze()) return 1;
if (show_progress) std::cout << "Generating...\n";
Compiler codegen(std::make_unique<SemanticAnalyzer>(std::move(analyzer)));
codegen.optimize_string();
codegen.generate();
codegen.write_file(output);
return 0;
}