From 8f98dc579af1993ec85bd849656c4835b4039dd6 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Mon, 23 Feb 2026 22:18:22 -0500 Subject: [willow]: frontend plumbing (#13) ... --- willow/tools/willowc/lib/driver.cpp | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'willow/tools/willowc/lib/driver.cpp') diff --git a/willow/tools/willowc/lib/driver.cpp b/willow/tools/willowc/lib/driver.cpp index e69de29..1962da4 100644 --- a/willow/tools/willowc/lib/driver.cpp +++ b/willow/tools/willowc/lib/driver.cpp @@ -0,0 +1,76 @@ +#include +#include +#include + +#include + +namespace willowc { + +int willowc_main(int argc, char **argv) { + argparse::ArgumentParser cl("willowc"); + cl.set_prefix_chars("-"); + cl.set_assign_chars("="); + + willowc::Compiler compiler; + + auto &ll = cl.add_mutually_exclusive_group(); + ll.add_argument("-Lerror") + .help("only emit diagnostics on error (default)") + .default_value(true) + .implicit_value(true) + .action( + [&](const auto &) { compiler.setLogLevel(willow::Severity::Error); }); + ll.add_argument("-Lwarn") + .help("emit warning messages") + .default_value(false) + .implicit_value(true) + .action([&](const auto &) { + compiler.setLogLevel(willow::Severity::Warning); + }); + ll.add_argument("-Linfo") + .help("emit remarks") + .default_value(false) + .implicit_value(true) + .action([&](const auto &) { + compiler.setLogLevel(willow::Severity::Remark); + }); + ll.add_argument("-Ldebug") + .help("emit all diagnostics") + .default_value(false) + .implicit_value(true) + .action( + [&](const auto &) { compiler.setLogLevel(willow::Severity::Debug); }); + + cl.add_argument("").help("input file path").required().nargs(1); + + if (argc < 2) { + std::cerr << cl; + return 1; + } + + try { + cl.parse_args(argc, argv); + } catch (std::exception &e) { + std::println("error: {}", e.what()); + } + + std::string f; + try { + f = cl.get(""); + } catch (std::exception &e) { + std::println("error: {}", e.what()); + return 1; + } + + if (f == "-") { + if (willow::failed(compiler.addStdIn())) + return 1; + } else if (willow::failed(compiler.addSourceFile(f))) + return 1; + + compiler.run(); + + return 0; +} + +} // namespace willowc -- cgit v1.2.3