[pypy-svn] r34039 - in pypy/dist/pypy/jit/codegen/llvm: . lib test
ericvrp at codespeak.net
ericvrp at codespeak.net
Wed Nov 1 16:35:36 CET 2006
Author: ericvrp
Date: Wed Nov 1 16:35:35 2006
New Revision: 34039
Added:
pypy/dist/pypy/jit/codegen/llvm/test/mul2.ll
Modified:
pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.cpp
pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.h
pypy/dist/pypy/jit/codegen/llvm/llvmjit.py
pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py
Log:
(ericvrp, mwh around) support for multiple modules in execution engine
Modified: pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.cpp
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.cpp (original)
+++ pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.cpp Wed Nov 1 16:35:35 2006
@@ -20,39 +20,51 @@
using namespace llvm;
-int testme(int n) {
- return n * 2;
-}
+ExecutionEngine* g_execution_engine;
-void* compile(const char* filename) {
+int compile(const char* filename) {
std::string inputfile(filename);
//from llvm-as.cpp
Module* module(ParseAssemblyFile(inputfile + ".ll"));
- if (!module) return NULL;
+ if (!module) {
+ std::cerr << "Error: can not parse " << inputfile << ".ll\n" << std::flush;
+ return false;
+ }
std::ostream *Out = new std::ofstream((inputfile + ".bc").c_str(),
std::ios::out | std::ios::trunc | std::ios::binary);
WriteBytecodeToFile(module, *Out); //XXX what to do with the 3rd param (NoCompress)?
- return module;
+ ModuleProvider* module_provider = new ExistingModuleProvider(module);
+ if (!g_execution_engine) {
+ g_execution_engine = ExecutionEngine::create(module_provider, false);
+ } else {
+ g_execution_engine->addModuleProvider(module_provider);
+ }
+
+ return true;
}
-int execute(void* compiled, const char* funcname, int param) { //currently compiled=Module
- Module* module = (Module*)compiled;
- if (!module) {
- std::cerr << "Error: can not execute " << funcname << " in a non existing module\n" << std::flush;
- return -1;
- }
+int execute(const char* funcname, int param) { //currently compiled=Module
+ int err = -1;
- ExistingModuleProvider* module_provider = new ExistingModuleProvider(module);
- ExecutionEngine* EE = ExecutionEngine::create(module_provider, false);
+ if (!g_execution_engine) {
+ std::cerr << "Error: no llvm code compiled yet!\n" << std::flush;
+ return err;
+ }
std::vector<GenericValue> args;
args.push_back((void*)param);
- GenericValue gv = EE->runFunction(module->getNamedFunction(funcname), args);
+ Function* func = g_execution_engine->FindFunctionNamed(funcname);
+ if (!func) {
+ std::cerr << "Error: can not find function " << funcname << "\n" << std::flush;
+ return err;
+ }
+
+ GenericValue gv = g_execution_engine->runFunction(func, args);
return gv.IntVal;
}
Modified: pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.h
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.h (original)
+++ pypy/dist/pypy/jit/codegen/llvm/lib/libllvmjit.h Wed Nov 1 16:35:35 2006
@@ -4,9 +4,8 @@
extern "C" {
#endif
-int testme(int n);
-void* compile(const char* filename);
-int execute(void* compiled, const char* funcname, int param);
+int compile(const char* filename);
+int execute(const char* funcname, int param);
#ifdef __cplusplus
}
Modified: pypy/dist/pypy/jit/codegen/llvm/llvmjit.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/llvmjit.py (original)
+++ pypy/dist/pypy/jit/codegen/llvm/llvmjit.py Wed Nov 1 16:35:35 2006
@@ -21,14 +21,10 @@
llvmjit._FuncPtr = _FuncPtr
#exposed functions...
-testme = llvmjit.testme
-testme.restype = c_int
-testme.argtypes = [c_int]
-
compile = llvmjit.compile
-compile.restype = c_void_p
+compile.restype = c_int
compile.argtypes = [c_char_p]
execute = llvmjit.execute
execute.restype = c_int
-execute.argtypes = [c_void_p, c_char_p, c_int]
+execute.argtypes = [c_char_p, c_int]
Added: pypy/dist/pypy/jit/codegen/llvm/test/mul2.ll
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/llvm/test/mul2.ll Wed Nov 1 16:35:35 2006
@@ -0,0 +1,5 @@
+int %mul2(int %n) {
+block0:
+ %n2 = mul int %n, 2
+ ret int %n2
+}
Modified: pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py (original)
+++ pypy/dist/pypy/jit/codegen/llvm/test/test_llvmjit.py Wed Nov 1 16:35:35 2006
@@ -9,21 +9,31 @@
curdir = dirname(__file__)
square = join(curdir, 'square')
+mul2 = join(curdir, 'mul2')
-def test_testme():
- assert llvmjit.testme(10) == 20
+def execute(filename, funcname, param):
+ assert llvmjit.compile(filename)
+ return llvmjit.execute(funcname, param)
-def test_testme_compile():
+def test_execute_compile():
def f(x):
- return llvmjit.testme(20+x)
+ return execute(square, 'square', x + 5)
fn = compile(f, [int])
res = fn(1)
- assert res == 42
+ assert res == 36
def test_compile():
assert llvmjit.compile(square)
def test_compiled():
- compiled = llvmjit.compile(square)
- assert llvmjit.execute(compiled, 'square', 4) == 4 * 4
+ assert execute(square, 'square', 4) == 4 * 4
+def test_compiled2():
+ llvmjit.compile(square)
+ llvmjit.compile(mul2)
+ for i in range(5):
+ assert llvmjit.execute('square', i) == i * i
+ assert llvmjit.execute('mul2', i) == i * 2
+
+def DONTtest_execute_accross_module():
+ pass
More information about the Pypy-commit
mailing list