diff options
| -rw-r--r-- | CMakeLists.txt | 9 | ||||
| -rw-r--r-- | tools/driver/main.cc | 25 |
2 files changed, 27 insertions, 7 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index e63860b..b2cead4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,12 @@ cmake_minimum_required(VERSION 3.13) project(cps_compiler) +set(CPSC_RUN_MODE "" CACHE STRING "Execution mode: PATH or NONE (required)") +set_property(CACHE CPSC_RUN_MODE PROPERTY STRINGS PATH NONE) +if(NOT CPSC_RUN_MODE MATCHES "^(PATH|NONE)$") + message(FATAL_ERROR "Specify -DCPSC_RUN_MODE=PATH or -DCPSC_RUN_MODE=NONE") +endif() + find_package(LLVM REQUIRED CONFIG) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") @@ -33,9 +39,10 @@ add_library(CPSCodeGen lib/CodeGen/FileHandler.cc ) -llvm_map_components_to_libnames(llvm_libs core support native irreader) +llvm_map_components_to_libnames(llvm_libs core support) add_executable(cpsc tools/driver/main.cc) +target_compile_definitions(cpsc PRIVATE CPSC_RUN_${CPSC_RUN_MODE}) target_link_libraries(cpsc CPSCodeGen CPSParser diff --git a/tools/driver/main.cc b/tools/driver/main.cc index a6b977a..f5373a0 100644 --- a/tools/driver/main.cc +++ b/tools/driver/main.cc @@ -48,6 +48,20 @@ int main(int argc, char **argv) { llvm::errs() << "Error: no source file specified\n"; return 1; } + std::string LliPath; + if (Run) { +#ifdef CPSC_RUN_PATH + auto Lli = llvm::sys::findProgramByName("lli"); + if (!Lli) { + llvm::errs() << "Error: -r requires lli in PATH: " << Lli.getError().message() << "\n"; + return 1; + } + LliPath = *Lli; +#else + llvm::errs() << "Error: -r is disabled in this build (CPSC_RUN_MODE=NONE)\n"; + return 1; +#endif + } if (OutputPath.empty() && !Run) { llvm::SmallString<256> DefaultPath(InputPath); llvm::sys::path::replace_extension(DefaultPath, ".ir"); @@ -108,18 +122,14 @@ int main(int argc, char **argv) { } if (!Run) return 0; - auto Lli = llvm::sys::findProgramByName("lli"); - if (!Lli) { - llvm::errs() << "Error: cannot find lli in PATH: " << Lli.getError().message() << "\n"; - return 1; - } +#ifdef CPSC_RUN_PATH llvm::SmallString<256> RunPath(OutputPath); if (auto PathError = llvm::sys::fs::make_absolute(RunPath)) { llvm::errs() << "Error: cannot resolve IR path: " << PathError.message() << "\n"; return 1; } std::string ExecutionError; - int Result = llvm::sys::ExecuteAndWait(*Lli, {*Lli, RunPath}, + int Result = llvm::sys::ExecuteAndWait(LliPath, {LliPath, RunPath}, std::nullopt, {}, 0, 0, &ExecutionError); if (Result < 0) { llvm::errs() << "Error: lli execution failed (status " << Result << "): " @@ -127,4 +137,7 @@ int main(int argc, char **argv) { return 1; } return Result; +#else + return 0; +#endif } |
