-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
60 lines (51 loc) · 1.9 KB
/
main.cpp
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
54
55
56
57
58
59
60
#include <utils/CodeGeneration.hpp>
#include <utils/termcolor.hpp>
#include <iostream>
#include <cstring>
#include <utils/TextManipulation.hpp>
using namespace dua;
bool is_dua_file(const std::string& str) {
return ends_with(str, ".dua");
}
int main(int argc, char* argv[])
{
if (argc == 1)
{
std::cout << termcolor::red << "Fatal error" <<
termcolor::reset << ": no input files. Run " <<
termcolor::green << argv[0] << " --help" <<
termcolor::reset << " for details.\n";
return 1;
}
for (int i = 1; i < argc; i++) {
if (std::strcmp(argv[i], "--help") == 0)
{
std::cout << "\nUSAGE: " <<
termcolor::green << argv[0] <<
termcolor::reset << " [options] file...\n\n";
std::cout << "Popular Options:\n"
" -S Generate assembly-code files (run compilation steps only)\n"
" -c Generate object files\n"
" -emit-llvm Generate LLVM IR code files (used along with the -S flag)\n"
" --target=<value> Generate code for the given target (<value> = target triple)\n\n";
std::cout << "Note: the Dua compiler is based on clang. This means that you can pass post-IR-generation "
"clang options\n";
return 0;
}
}
bool include_dua_lib = true;
std::vector<std::string> args;
std::vector<std::string> source_files;
for (int i = 1; i < argc; i++) {
if (is_dua_file(argv[i]))
source_files.emplace_back(argv[i]);
else {
if (strcmp(argv[i], "-no-libdua") == 0)
include_dua_lib = false;
else
args.emplace_back(argv[i]);
}
}
compile(source_files, args, include_dua_lib);
return 0;
}