aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-13 03:51:54 +0000
committer_ov4 <ov4@ov4.org>2026-10-13 03:51:54 +0000
commitba1b65f4a20566405c53d4ded90b483ec9aa7d09 (patch)
tree4524a14d5398a3d46be188b30f672b808419f1b4 /tools
parentf0780bf173ddfdb7ebbf2c7cd2ffd2e447379a65 (diff)
feat: require explicit execution mode and gate external running
Require PATH or NONE at configure time. Reject -r before writing output when lli is unavailable or execution is disabled. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/driver/main.cc25
1 files changed, 19 insertions, 6 deletions
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
}