Skip to content

Commit

Permalink
feat: ability disable codegen and only verify
Browse files Browse the repository at this point in the history
  • Loading branch information
JaDogg committed Mar 24, 2024
1 parent ab38d6d commit c5dd614
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions compiler/src/comp_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}

0 comments on commit c5dd614

Please sign in to comment.