summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-06-01 23:48:45 +0000
committerChris Lattner <sabre@nondot.org>2004-06-01 23:48:45 +0000
commit10d7d569dbcaa8a35694ae79d63d90976f8bf6fe (patch)
tree65483209807ed5a48d2bf11a1d95339e1595328d /llvm
parent8e71bc09ff4a66489b4be4aad8f29a31b164fc02 (diff)
downloadbcm5719-llvm-10d7d569dbcaa8a35694ae79d63d90976f8bf6fe.tar.gz
bcm5719-llvm-10d7d569dbcaa8a35694ae79d63d90976f8bf6fe.zip
Initial checkin of a stub executable that can be used by gccld to forward to
bytecode files on systems that don't support #!/bin/sh natively (ie, win32). llvm-svn: 13937
Diffstat (limited to 'llvm')
-rw-r--r--llvm/tools/llvm-stub/Makefile13
-rw-r--r--llvm/tools/llvm-stub/llvm-stub.c51
2 files changed, 64 insertions, 0 deletions
diff --git a/llvm/tools/llvm-stub/Makefile b/llvm/tools/llvm-stub/Makefile
new file mode 100644
index 00000000000..befcb6cc2ec
--- /dev/null
+++ b/llvm/tools/llvm-stub/Makefile
@@ -0,0 +1,13 @@
+##===- tools/llvm-stub/Makefile ----------------------------*- Makefile -*-===##
+#
+# The LLVM Compiler Infrastructure
+#
+# This file was developed by the LLVM research group and is distributed under
+# the University of Illinois Open Source License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+TOOLNAME = llvm-stub
+include $(LEVEL)/Makefile.common
+
diff --git a/llvm/tools/llvm-stub/llvm-stub.c b/llvm/tools/llvm-stub/llvm-stub.c
new file mode 100644
index 00000000000..7009c8dee1a
--- /dev/null
+++ b/llvm/tools/llvm-stub/llvm-stub.c
@@ -0,0 +1,51 @@
+/*===- llvm-stub.c - Stub executable to run llvm bytecode files -----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This tool is used by the gccld program to enable transparent execution of
+// bytecode files by the user. Specifically, gccld outputs two files when asked
+// to compile a <program> file:
+// 1. It outputs the LLVM bytecode file to <program>.bc
+// 2. It outputs a stub executable that runs lli on <program>.bc
+//
+// This allows the end user to just say ./<program> and have the JIT executed
+// automatically. On unix, the stub executable emitted is actually a bourne
+// shell script that does the forwarding. Windows doesn't not like #!/bin/sh
+// programs in .exe files, so we make it an actual program, defined here.
+//
+//===----------------------------------------------------------------------===*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "Config/unistd.h" /* provides definition of execve */
+
+int main(int argc, char** argv) {
+ const char *Interp = getenv("LLVMINTERP");
+ const char **Args;
+ if (Interp == 0) Interp = "lli";
+
+ /* Set up the command line options to pass to the JIT. */
+ Args = (const char**)malloc(sizeof(char*) * (argc+2));
+ /* argv[0] is the JIT */
+ Args[0] = Interp;
+ /* argv[1] is argv[0] + ".bc". */
+ Args[1] = strcat(strcpy((char*)malloc(strlen(argv[0])+4), argv[0]), ".bc");
+
+ /* The rest of the args are as before. */
+ memcpy(Args+2, argv+1, sizeof(char*)*argc);
+
+ /* Run the JIT. */
+ execvp(Interp, (char *const*)Args);
+
+ /* if _execv returns, the JIT could not be started. */
+ fprintf(stderr, "Could not execute the LLVM JIT. Either add 'lli' to your"
+ " path, or set the\ninterpreter you want to use in the LLVMINTERP "
+ "environment variable.\n");
+ return 1;
+}
OpenPOWER on IntegriCloud