From c5dd614928970bb15af4bf2d385b6bfac433a5c9 Mon Sep 17 00:00:00 2001 From: JaDogg Date: Sun, 24 Mar 2024 14:19:37 +0000 Subject: [PATCH] feat: ability disable codegen and only verify --- compiler/src/comp_main.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/compiler/src/comp_main.cpp b/compiler/src/comp_main.cpp index a2d6727e..4882362e 100644 --- a/compiler/src/comp_main.cpp +++ b/compiler/src/comp_main.cpp @@ -50,7 +50,10 @@ int main(int argc, char *argv[]) { argparser::ARGS(PROGRAM_NAME, "Compile Yaksha code to C code", ""); auto help = argparser::OP_BOOL('h', "--help", "Print this help message"); auto no_main = argparser::OP_BOOL('N', "--no-main", "Disable main() check"); - args.optional_ = {&help, &no_main}; + auto no_codegen = + argparser::OP_BOOL('d', "--disable-codegen", + "Do not output generated code, instead just print errors."); + args.optional_ = {&help, &no_main, &no_codegen}; auto code = argparser::PO("mainfile.yaka", "Yaksha code file."); auto lib = argparser::PO_OPT("[LIBS_PARENT_PATH]", "Path to the parent directory of the libraries"); @@ -70,13 +73,17 @@ int main(int argc, char *argv[]) { try { mc.main_required_ = !no_main.is_set_; codegen_c cg{}; + do_nothing_codegen dn_cg{}; + codegen *cg_ptr = &cg; + codegen *dn_cg_ptr = &dn_cg; + codegen *codegen = (no_codegen.is_set_) ? dn_cg_ptr : cg_ptr; if (!lib.is_set_) {// Just code.yaka is passed - result = mc.compile(code.value_, &cg); + result = mc.compile(code.value_, codegen); } else {// code.yaka + LIBS_PARENT_PATH - result = mc.compile(code.value_, lib.value_, &cg); + result = mc.compile(code.value_, lib.value_, codegen); } if (result.failed_) { return EXIT_FAILURE; } } catch (parsing_error &e) { mc.error_printer_.print_errors({e}); } - std::cout << result.code_; + if (!no_codegen.is_set_) { std::cout << result.code_; } return EXIT_SUCCESS; }