summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-10-25 22:58:53 +0000
committerChris Lattner <sabre@nondot.org>2002-10-25 22:58:53 +0000
commitddb1212d89fe9ab729848992053e06b87de24261 (patch)
tree4d78adb819912514deadbaa9db92252a2b0f28ae /tools
parent726140821f96e3472a8eccef0c67c0b5ad65a1d9 (diff)
downloadllvm-ddb1212d89fe9ab729848992053e06b87de24261.tar.gz
llvm-ddb1212d89fe9ab729848992053e06b87de24261.tar.bz2
llvm-ddb1212d89fe9ab729848992053e06b87de24261.tar.xz
Initial checkin of LLVM JIT, codenamed jello. This tool is not built by
default, until it becomes stable. Even then it will only work for for X86 targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4285 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/jello/Makefile10
-rw-r--r--tools/jello/jello.cpp76
2 files changed, 86 insertions, 0 deletions
diff --git a/tools/jello/Makefile b/tools/jello/Makefile
new file mode 100644
index 0000000000..3543c82b79
--- /dev/null
+++ b/tools/jello/Makefile
@@ -0,0 +1,10 @@
+LEVEL = ../..
+TOOLNAME = jello
+USEDLIBS = bcreader vmcore codegen x86 support.a target.a
+
+# Have gcc tell the linker to export symbols from the program so that
+# dynamically loaded modules can be linked against them.
+#
+TOOLLINKOPTS = -ldl $(ExportSymbols)
+
+include $(LEVEL)/Makefile.common
diff --git a/tools/jello/jello.cpp b/tools/jello/jello.cpp
new file mode 100644
index 0000000000..3cf83bce8d
--- /dev/null
+++ b/tools/jello/jello.cpp
@@ -0,0 +1,76 @@
+//===-- jello.cpp - LLVM Just in Time Compiler ----------------------------===//
+//
+// This tool implements a just-in-time compiler for LLVM, allowing direct
+// execution of LLVM bytecode in an efficient manner.
+//
+// FIXME: This code will get more object oriented as we get the call back
+// intercept stuff implemented.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Module.h"
+#include "llvm/Bytecode/Reader.h"
+#include "llvm/CodeGen/MFunction.h"
+#include "../lib/Target/X86/X86.h" // FIXME: become generic eventually
+#include "../lib/Target/X86/X86InstructionInfo.h"
+#include "Support/CommandLine.h"
+#include "Support/Statistic.h"
+
+namespace {
+ cl::opt<std::string>
+ InputFile(cl::desc("<input bytecode>"), cl::Positional, cl::init("-"));
+
+ cl::opt<std::string>
+ MainFunction("f", cl::desc("Function to execute"), cl::init("main"),
+ cl::value_desc("function name"));
+}
+
+
+/// ExecuteFunction - Compile the specified function to machine code, and
+/// execute it.
+///
+static void ExecuteFunction(Function &F) {
+ X86InstructionInfo II;
+
+ // Perform instruction selection to turn the function into an x86 SSA form
+ MFunction *MF = X86SimpleInstructionSelection(F);
+
+ // TODO: optional optimizations go here
+
+ // If -debug is specified, output selected code to stderr
+ /*DEBUG*/(MF->print(std::cerr, II));
+
+ // Perform register allocation to convert to a concrete x86 representation
+ X86SimpleRegisterAllocation(MF);
+
+ // If -debug is specified, output compiled code to stderr
+ /*DEBUG*/(X86PrintCode(MF, std::cerr));
+
+ // Emit register allocated X86 code now...
+ void *PFun = X86EmitCodeToMemory(MF);
+
+ // We don't need the machine specific representation for this function anymore
+ delete MF;
+}
+
+
+//===----------------------------------------------------------------------===//
+// main Driver function
+//
+int main(int argc, char **argv) {
+ cl::ParseCommandLineOptions(argc, argv, " llvm just in time compiler\n");
+
+ std::string ErrorMsg;
+ if (Module *M = ParseBytecodeFile(InputFile, &ErrorMsg)) {
+ for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
+ if (I->getName() == MainFunction)
+ ExecuteFunction(*I);
+
+ delete M;
+ return 0;
+ }
+
+ std::cerr << "Error parsing '" << InputFile << "': " << ErrorMsg << "\n";
+ return 1;
+}
+