X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-stub%2Fllvm-stub.c;h=f2e478e69583b85d66f2a22ce4c08d14f8351442;hb=c22675b5428d579d4eca15ee8a0ff701942738c4;hp=7009c8dee1a1ff85e949ce455d715e6510e8094e;hpb=4c6d124efa433347c7280d4a075d954bd0231a78;p=oota-llvm.git diff --git a/tools/llvm-stub/llvm-stub.c b/tools/llvm-stub/llvm-stub.c index 7009c8dee1a..f2e478e6958 100644 --- a/tools/llvm-stub/llvm-stub.c +++ b/tools/llvm-stub/llvm-stub.c @@ -1,21 +1,21 @@ -/*===- llvm-stub.c - Stub executable to run llvm bytecode files -----------===// +/*===- llvm-stub.c - Stub executable to run llvm bitcode 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 file 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 +// bitcode files by the user. Specifically, gccld outputs two files when asked // to compile a file: -// 1. It outputs the LLVM bytecode file to .bc +// 1. It outputs the LLVM bitcode file to .bc // 2. It outputs a stub executable that runs lli on .bc // // This allows the end user to just say ./ 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 +// shell script that does the forwarding. Windows does not like #!/bin/sh // programs in .exe files, so we make it an actual program, defined here. // //===----------------------------------------------------------------------===*/ @@ -23,7 +23,17 @@ #include #include #include -#include "Config/unistd.h" /* provides definition of execve */ + +#include "llvm/Config/config.h" + +#if defined(HAVE_UNISTD_H) && !defined(_MSC_VER) +#include +#endif + +#ifdef _WIN32 +#include +#include +#endif int main(int argc, char** argv) { const char *Interp = getenv("LLVMINTERP"); @@ -34,15 +44,27 @@ int main(int argc, char** argv) { Args = (const char**)malloc(sizeof(char*) * (argc+2)); /* argv[0] is the JIT */ Args[0] = Interp; + +#ifdef LLVM_ON_WIN32 + { + int len = strlen(argv[0]); + if (len < 4 || strcmp(argv[0] + len - 4, ".exe") != 0) { + /* .exe suffix is stripped off of argv[0] if the executable was run on the + * command line without one. Put it back on. + */ + argv[0] = strcat(strcpy((char*)malloc(len + 5), argv[0]), ".exe"); + } + } +#endif + /* 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); + memcpy((char **)Args+2, argv+1, sizeof(char*)*argc); /* Run the JIT. */ - execvp(Interp, (char *const*)Args); - + execvp(Interp, (char **)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 "