3 #include "llvm/Support/CommandLine.h"
7 #include "driver/driver.h"
9 namespace cmd = llvm::cl;
10 namespace fs = std::filesystem;
11 using namespace tanlang;
13 int cli_main(
int argc,
char **argv) {
15 cmd::OptionCategory cl_category(
"tanc");
16 cmd::opt<str> opt_output_file(
17 "o", cmd::desc(
"Output filename"), cmd::value_desc(
"output"), cmd::init(
"a.out"), cmd::cat(cl_category));
18 cmd::list<str> opt_link_libraries(
19 "l", cmd::desc(
"Libraries to link against"), cmd::value_desc(
"libraries"), cmd::Prefix, cmd::cat(cl_category));
20 cmd::list<str> opt_library_path(
"L", cmd::desc(
"Library search path"), cmd::Prefix, cmd::cat(cl_category));
21 cmd::list<str> opt_source_files(cmd::Positional,
23 cmd::desc(
"Files to compile"),
24 cmd::value_desc(
"<source files>"),
26 cmd::cat(cl_category));
27 cmd::list<str> opt_import_dirs(
"I", cmd::desc(
"Import search directories"), cmd::Prefix, cmd::cat(cl_category));
28 cmd::opt<bool> opt_print_ir_code(
"print-ir", cmd::desc(
"Print LLVM IR code"), cmd::cat(cl_category));
29 cmd::opt<bool> opt_print_ast(
"print-ast", cmd::desc(
"Print abstract syntax tree"), cmd::cat(cl_category));
30 cmd::opt<TanCompileType> opt_output_type(cmd::desc(
"Output type"),
31 cmd::values(clEnumValN(DLIB,
"shared",
"Shared library"),
32 clEnumValN(SLIB,
"static",
"Static library"),
33 clEnumValN(EXE,
"exe",
"Executable"),
34 clEnumValN(OBJ,
"obj",
"Object file")),
36 cmd::cat(cl_category));
37 cmd::opt<TanOptLevel> opt_optimization_level(cmd::desc(
"Optimization level"),
38 cmd::values(clEnumValN(O0,
"g",
"None"),
39 clEnumVal(O0,
"None"),
40 clEnumVal(O1,
"Less"),
41 clEnumVal(O2,
"Default"),
42 clEnumVal(O3,
"Aggressive")),
44 cmd::cat(cl_category));
54 cmd::HideUnrelatedOptions(cl_category);
57 cmd::ParseCommandLineOptions(
58 argc, argv, fmt::format(
"tanc version: {}.{}.{} \n", TAN_VERSION[0], TAN_VERSION[1], TAN_VERSION[2]));
59 vector<str> source_files(opt_source_files);
62 if (!init_compiler(argc, argv)) {
64 throw std::runtime_error(
"Unable to init tanc compiler");
70 config.
out_file = opt_output_file.getValue();
71 config.
lib_dirs = vector<str>(opt_library_path);
72 config.
link_files = vector<str>(opt_link_libraries);
74 config.type = opt_output_type.getValue();
75 config.
opt_level = opt_optimization_level.getValue();
80 }
else if (opt_print_ir_code) {
85 cmd::ResetCommandLineParser();
90 driver.run(source_files);
95 std::cerr << e.what() <<
'\n';
Compile a list of C++ and/or tan source files, and perform linking.
Compilation configuration.
vector< str > import_dirs
Library search paths.
unsigned verbose
Optimization level,.
str out_file
Verbose level, 0 non-verbose, 1 print LLVM IR, 2, print LLVM IR and abstract syntax tree.
vector< str > link_files
Output filename, invalid if TanCompilation::type is set to OBJ.
TanOptLevel opt_level
Type of compilation,.
vector< str > lib_dirs
Files to link against.