aboutsummaryrefslogtreecommitdiff
path: root/tools/driver/main.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-13 03:54:49 +0000
committer_ov4 <ov4@ov4.org>2026-10-13 03:54:49 +0000
commite28cbb2efac9ed6e56cd9ab6eb1a3f16810d575a (patch)
treea0402247ba92259f6b7f3a2ad2c8ed0ca8eab3de /tools/driver/main.cc
parentba1b65f4a20566405c53d4ded90b483ec9aa7d09 (diff)
feat: embed a statically linked LLVM execution engine
Add EMBEDDED mode to run generated modules in-process without lli or PATH lookup. Link LLVM and support archives plus the C++ runtime statically, while retaining the system C runtime on Linux. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'tools/driver/main.cc')
-rw-r--r--tools/driver/main.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/tools/driver/main.cc b/tools/driver/main.cc
index f5373a0..4df8562 100644
--- a/tools/driver/main.cc
+++ b/tools/driver/main.cc
@@ -1,6 +1,9 @@
#include "cps/Lexer.h"
#include "cps/Parser.h"
#include "cps/CodeGen.h"
+#ifdef CPSC_RUN_EMBEDDED
+#include "EmbeddedRunner.h"
+#endif
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/FileUtilities.h"
@@ -48,7 +51,9 @@ int main(int argc, char **argv) {
llvm::errs() << "Error: no source file specified\n";
return 1;
}
+#ifdef CPSC_RUN_PATH
std::string LliPath;
+#endif
if (Run) {
#ifdef CPSC_RUN_PATH
auto Lli = llvm::sys::findProgramByName("lli");
@@ -57,7 +62,7 @@ int main(int argc, char **argv) {
return 1;
}
LliPath = *Lli;
-#else
+#elif defined(CPSC_RUN_NONE)
llvm::errs() << "Error: -r is disabled in this build (CPSC_RUN_MODE=NONE)\n";
return 1;
#endif
@@ -93,6 +98,9 @@ int main(int argc, char **argv) {
if (CG.hadError()) return 1;
+#ifdef CPSC_RUN_EMBEDDED
+ if (Run && OutputPath.empty()) return runEmbedded(CG);
+#endif
std::error_code EC;
int OutputFD;
llvm::FileRemover TemporaryOutput;
@@ -137,6 +145,8 @@ int main(int argc, char **argv) {
return 1;
}
return Result;
+#elif defined(CPSC_RUN_EMBEDDED)
+ return runEmbedded(CG);
#else
return 0;
#endif