[pypy-svn] r25248 - in pypy/dist/pypy/translator/llvm: llvmcapi/include llvmcapi/include/ExecutionEngine llvmcapi/include/VMCore llvmcapi/lib llvmcapi/lib/ExecutionEngine llvmcapi/lib/VMCore pythonllvm pythonllvm/test
ericvrp at codespeak.net
ericvrp at codespeak.net
Mon Apr 3 13:28:30 CEST 2006
Author: ericvrp
Date: Mon Apr 3 13:28:26 2006
New Revision: 25248
Added:
pypy/dist/pypy/translator/llvm/llvmcapi/include/ExecutionEngine/GenericValue.h
pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/DerivedTypes.h
pypy/dist/pypy/translator/llvm/llvmcapi/lib/ExecutionEngine/GenericValue.cpp (contents, props changed)
pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/DerivedTypes.cpp (contents, props changed)
Modified:
pypy/dist/pypy/translator/llvm/llvmcapi/include/ExecutionEngine/ExecutionEngine.h
pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/Function.h
pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/Module.h
pypy/dist/pypy/translator/llvm/llvmcapi/include/llvmcapi.h
pypy/dist/pypy/translator/llvm/llvmcapi/lib/ExecutionEngine/ExecutionEngine.cpp
pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/Function.cpp
pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/Module.cpp
pypy/dist/pypy/translator/llvm/llvmcapi/lib/llvmcapi.cpp
pypy/dist/pypy/translator/llvm/pythonllvm/helper.py
pypy/dist/pypy/translator/llvm/pythonllvm/llvmcapi.py
pypy/dist/pypy/translator/llvm/pythonllvm/pyllvm.py
pypy/dist/pypy/translator/llvm/pythonllvm/test/test_ee.py
Log:
More llvm c api support
Modified: pypy/dist/pypy/translator/llvm/llvmcapi/include/ExecutionEngine/ExecutionEngine.h
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmcapi/include/ExecutionEngine/ExecutionEngine.h (original)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/include/ExecutionEngine/ExecutionEngine.h Mon Apr 3 13:28:26 2006
@@ -11,8 +11,10 @@
*/
void* ExecutionEngine__create__(void* MP, int ForceInterpreter);
void* ExecutionEngine_getModule(void* EE);
-int ExecutionEngine_n_functions(void* EE);
-int ExecutionEngine_function_exists(void* EE, const char* funcname);
+void ExecutionEngine_freeMachineCodeForFunction(void* EE, void* F);
+
+// return union and takes std::vector<GenericValue> actually
+int ExecutionEngine_runFunction(void* EE, void* F, int args_vector);
#ifdef __cplusplus
};
Added: pypy/dist/pypy/translator/llvm/llvmcapi/include/ExecutionEngine/GenericValue.h
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/include/ExecutionEngine/GenericValue.h Mon Apr 3 13:28:26 2006
@@ -0,0 +1,14 @@
+#ifndef __GENERICVALUE_H__
+#define __GENERICVALUE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void* GenericValue__init__();
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif
Added: pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/DerivedTypes.h
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/DerivedTypes.h Mon Apr 3 13:28:26 2006
@@ -0,0 +1,16 @@
+#ifndef __DERIVEDTYPES_H__
+#define __DERIVEDTYPES_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int FunctionType_getNumParams(void* FT);
+const void* FunctionType_getParamType(void* FT, int i);
+const void* FunctionType_getReturnType(void* FT);
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif
Modified: pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/Function.h
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/Function.h (original)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/Function.h Mon Apr 3 13:28:26 2006
@@ -5,7 +5,8 @@
extern "C" {
#endif
-//
+void Function_eraseFromParent(void* F);
+const void* Function_getFunctionType(void* F);
#ifdef __cplusplus
};
Modified: pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/Module.h
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/Module.h (original)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/include/VMCore/Module.h Mon Apr 3 13:28:26 2006
@@ -5,20 +5,23 @@
extern "C" {
#endif
-void* Module__init__(const char* ModuleID);
+void* Module__init__(const char* ModuleID);
const char* Module_getModuleIdentifier(void* M);
void Module_setModuleIdentifier(void* M, const char* ID);
const char* Module_getTargetTriple(void* M);
void Module_setTargetTriple(void* M, const char* T);
-//const char* Module_getEndianness(void* M);
-//void Module_setEndianness(void* M, Endianness E);
-//const char* Module_getPointerSize(void* M);
-//void Module_setPointerSize(void* M, PointerSize PS);
const char* Module_getModuleInlineAsm(void* M);
void Module_setModuleInlineAsm(void* M, const char* Asm);
+void* Module_getNamedFunction(void* M, const char* fnname);
+
+// global function that seem to better fit here
void Module_ParseAssemblyString(void* M, const char* AsmString);
int Module_verifyModule(void* M);
+// helpers
+int Module_n_functions(void* M);
+int Module_function_exists(void* M, const char* fnname);
+
#ifdef __cplusplus
};
#endif
Modified: pypy/dist/pypy/translator/llvm/llvmcapi/include/llvmcapi.h
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmcapi/include/llvmcapi.h (original)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/include/llvmcapi.h Mon Apr 3 13:28:26 2006
@@ -8,7 +8,9 @@
#include "VMCore/Module.h"
#include "VMCore/ModuleProvider.h"
#include "VMCore/Function.h"
+#include "VMCore/DerivedTypes.h"
#include "ExecutionEngine/ExecutionEngine.h"
+#include "ExecutionEngine/GenericValue.h"
void toggle_print_machineinstrs();
Modified: pypy/dist/pypy/translator/llvm/llvmcapi/lib/ExecutionEngine/ExecutionEngine.cpp
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmcapi/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/lib/ExecutionEngine/ExecutionEngine.cpp Mon Apr 3 13:28:26 2006
@@ -20,27 +20,15 @@
return &((ExecutionEngine*)EE)->getModule();
}
-int ExecutionEngine_n_functions(void* EE) { //move to Module?
- Module* mod = &((ExecutionEngine*)EE)->getModule();
- int funccount = 0;
- Module::FunctionListType &fns = mod->getFunctionList();
- for (Module::FunctionListType::const_iterator ii = fns.begin(); ii != fns.end(); ++ii) {
- if (!(ii->isIntrinsic() || ii->isExternal())) {
- funccount += 1;
- }
- }
- return funccount;
+void ExecutionEngine_freeMachineCodeForFunction(void* EE, void* F) {
+ ExecutionEngine* ee = (ExecutionEngine*)EE;
+ Function* f = (Function*)F;
+ ee->freeMachineCodeForFunction(f);
}
-int Module_function_exists(void* EE, const char* funcname) { //move to Module?
- Module* mod = &((ExecutionEngine*)EE)->getModule();
- Module::FunctionListType &fns = mod->getFunctionList();
- for (Module::FunctionListType::const_iterator ii = fns.begin(); ii != fns.end(); ++ii) {
- if (!(ii->isIntrinsic() || ii->isExternal())) {
- if (ii->getName() == funcname) {
- return 1;
- }
- }
- }
- return 0;
+int ExecutionEngine_runFunction(void* EE, void* F, int args_vector) {
+ ExecutionEngine* ee = (ExecutionEngine*)EE;
+ Function* f = (Function*)F;
+ std::vector<GenericValue> args;
+ return ee->runFunction(f, args).IntVal;
}
Added: pypy/dist/pypy/translator/llvm/llvmcapi/lib/ExecutionEngine/GenericValue.cpp
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/lib/ExecutionEngine/GenericValue.cpp Mon Apr 3 13:28:26 2006
@@ -0,0 +1,7 @@
+#include "llvm/ExecutionEngine/GenericValue.h"
+
+using namespace llvm;
+
+void* GenericValue__init__() {
+ return new GenericValue();
+}
Added: pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/DerivedTypes.cpp
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/DerivedTypes.cpp Mon Apr 3 13:28:26 2006
@@ -0,0 +1,18 @@
+#include "llvm/DerivedTypes.h"
+
+using namespace llvm;
+
+int FunctionType_getNumParams(void* FT) {
+ FunctionType* ft = (FunctionType*)FT;
+ return ft->getNumParams();
+}
+
+const void* FunctionType_getParamType(void* FT, int i) {
+ FunctionType* ft = (FunctionType*)FT;
+ return ft->getParamType(i);
+}
+
+const void* FunctionType_getReturnType(void* FT) {
+ FunctionType* ft = (FunctionType*)FT;
+ return ft->getReturnType();
+}
Modified: pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/Function.cpp
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/Function.cpp (original)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/Function.cpp Mon Apr 3 13:28:26 2006
@@ -2,6 +2,12 @@
using namespace llvm;
-//void* Function__init__(void* M) {
-// return new Function((Module*)M);
-//}
+void Function_eraseFromParent(void* F) {
+ Function* f = (Function*)F;
+ f->eraseFromParent();
+}
+
+const void* Function_getFunctionType(void* F) {
+ Function* f = (Function*)F;
+ return f->getFunctionType();
+}
Modified: pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/Module.cpp
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/Module.cpp (original)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/lib/VMCore/Module.cpp Mon Apr 3 13:28:26 2006
@@ -23,24 +23,6 @@
return ((Module*)M)->setTargetTriple(T);
}
-/*
-const char* Module_getEndianness(void* M) {
- return ((Module*)M)->getEndianness().c_str();
-}
-
-void Module_setEndianness(void* M, Endianness E) {
- return ((Module*)M)->setEndianness(E);
-}
-
-const char* Module_getPointerSize(void* M) {
- return ((Module*)M)->getPointerSize().c_str();
-}
-
-void Module_setPointerSize(void* M, PointerSize PS) {
- return ((Module*)M)->setPointerSize(PS);
-}
-*/
-
const char* Module_getModuleInlineAsm(void* M) {
return ((Module*)M)->getModuleInlineAsm().c_str();
}
@@ -49,6 +31,11 @@
((Module*)M)->setModuleInlineAsm(Asm);
}
+void* Module_getNamedFunction(void* M, const char* fnname) {
+ return ((Module*)M)->getNamedFunction(fnname);
+}
+
+// global functions, but they make more sense here
void Module_ParseAssemblyString(void* M, const char* AsmString) { //from Assembly/Parser.h
ParseAssemblyString(AsmString, (Module*)M);
}
@@ -56,3 +43,29 @@
int Module_verifyModule(void* M) { //from Analysis/Verifier.h
return verifyModule(*(Module*)M, ThrowExceptionAction);
}
+
+// helpers
+int Module_n_functions(void* M) {
+ Module* mod = (Module*)M;
+ int funccount = 0;
+ Module::FunctionListType &fns = mod->getFunctionList();
+ for (Module::FunctionListType::const_iterator ii = fns.begin(); ii != fns.end(); ++ii) {
+ if (!(ii->isIntrinsic() || ii->isExternal())) {
+ funccount += 1;
+ }
+ }
+ return funccount;
+}
+
+int Module_function_exists(void* M, const char* fnname) {
+ Module* mod = (Module*)M;
+ Module::FunctionListType &fns = mod->getFunctionList();
+ for (Module::FunctionListType::const_iterator ii = fns.begin(); ii != fns.end(); ++ii) {
+ if (!(ii->isIntrinsic() || ii->isExternal())) {
+ if (ii->getName() == fnname) {
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
Modified: pypy/dist/pypy/translator/llvm/llvmcapi/lib/llvmcapi.cpp
==============================================================================
--- pypy/dist/pypy/translator/llvm/llvmcapi/lib/llvmcapi.cpp (original)
+++ pypy/dist/pypy/translator/llvm/llvmcapi/lib/llvmcapi.cpp Mon Apr 3 13:28:26 2006
@@ -22,7 +22,9 @@
#include "VMCore/Module.cpp"
#include "VMCore/ModuleProvider.cpp"
#include "VMCore/Function.cpp"
+#include "VMCore/DerivedTypes.cpp"
#include "ExecutionEngine/ExecutionEngine.cpp"
+#include "ExecutionEngine/GenericValue.cpp"
void toggle_print_machineinstrs() {
Modified: pypy/dist/pypy/translator/llvm/pythonllvm/helper.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/pythonllvm/helper.py (original)
+++ pypy/dist/pypy/translator/llvm/pythonllvm/helper.py Mon Apr 3 13:28:26 2006
@@ -10,12 +10,11 @@
def __call__(self, *args):
a = [self.instance]
- #for arg in args:
- # if isinstance(arg, Wrapper): #pass on value to actual C (not Python) object
- # a.append(arg.instance)
- # else:
- # a.append(arg)
- a += args
+ for arg in args:
+ if isinstance(arg, Wrapper): #pass on value to actual C (not Python) object
+ a.append(arg.instance)
+ else:
+ a.append(arg)
return apply(self.method, a)
class Wrapper(object):
Modified: pypy/dist/pypy/translator/llvm/pythonllvm/llvmcapi.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/pythonllvm/llvmcapi.py (original)
+++ pypy/dist/pypy/translator/llvm/pythonllvm/llvmcapi.py Mon Apr 3 13:28:26 2006
@@ -17,10 +17,52 @@
ExecutionEngine_getModule = cdecl(c_void_p, 'llvmcapi', [c_void_p]) (ExecutionEngine_getModule)
-def ExecutionEngine_n_functions(EE):
+def ExecutionEngine_freeMachineCodeForFunction(EE, F):
# ../llvmcapi/include/ExecutionEngine/ExecutionEngine.h 14
- return ExecutionEngine_n_functions._api_(EE)
-ExecutionEngine_n_functions = cdecl(c_int, 'llvmcapi', [c_void_p]) (ExecutionEngine_n_functions)
+ return ExecutionEngine_freeMachineCodeForFunction._api_(EE, F)
+ExecutionEngine_freeMachineCodeForFunction = cdecl(None, 'llvmcapi', [c_void_p, c_void_p]) (ExecutionEngine_freeMachineCodeForFunction)
+
+
+def ExecutionEngine_runFunction(EE, F, args_vector):
+ # ../llvmcapi/include/ExecutionEngine/ExecutionEngine.h 17
+ return ExecutionEngine_runFunction._api_(EE, F, args_vector)
+ExecutionEngine_runFunction = cdecl(c_int, 'llvmcapi', [c_void_p, c_void_p, c_int]) (ExecutionEngine_runFunction)
+
+
+def GenericValue__init__():
+ # ../llvmcapi/include/ExecutionEngine/GenericValue.h 8
+ return GenericValue__init__._api_()
+GenericValue__init__ = cdecl(c_void_p, 'llvmcapi', []) (GenericValue__init__)
+
+
+def FunctionType_getNumParams(FT):
+ # ../llvmcapi/include/VMCore/DerivedTypes.h 8
+ return FunctionType_getNumParams._api_(FT)
+FunctionType_getNumParams = cdecl(c_int, 'llvmcapi', [c_void_p]) (FunctionType_getNumParams)
+
+
+def FunctionType_getParamType(FT, i):
+ # ../llvmcapi/include/VMCore/DerivedTypes.h 9
+ return FunctionType_getParamType._api_(FT, i)
+FunctionType_getParamType = cdecl(c_void_p, 'llvmcapi', [c_void_p, c_int]) (FunctionType_getParamType)
+
+
+def FunctionType_getReturnType(FT):
+ # ../llvmcapi/include/VMCore/DerivedTypes.h 10
+ return FunctionType_getReturnType._api_(FT)
+FunctionType_getReturnType = cdecl(c_void_p, 'llvmcapi', [c_void_p]) (FunctionType_getReturnType)
+
+
+def Function_eraseFromParent(F):
+ # ../llvmcapi/include/VMCore/Function.h 8
+ return Function_eraseFromParent._api_(F)
+Function_eraseFromParent = cdecl(None, 'llvmcapi', [c_void_p]) (Function_eraseFromParent)
+
+
+def Function_getFunctionType(F):
+ # ../llvmcapi/include/VMCore/Function.h 9
+ return Function_getFunctionType._api_(F)
+Function_getFunctionType = cdecl(c_void_p, 'llvmcapi', [c_void_p]) (Function_getFunctionType)
def Module__init__(ModuleID):
@@ -54,29 +96,47 @@
def Module_getModuleInlineAsm(M):
- # ../llvmcapi/include/VMCore/Module.h 17
+ # ../llvmcapi/include/VMCore/Module.h 13
return Module_getModuleInlineAsm._api_(M)
Module_getModuleInlineAsm = cdecl(STRING, 'llvmcapi', [c_void_p]) (Module_getModuleInlineAsm)
def Module_setModuleInlineAsm(M, Asm):
- # ../llvmcapi/include/VMCore/Module.h 18
+ # ../llvmcapi/include/VMCore/Module.h 14
return Module_setModuleInlineAsm._api_(M, Asm)
Module_setModuleInlineAsm = cdecl(None, 'llvmcapi', [c_void_p, STRING]) (Module_setModuleInlineAsm)
+def Module_getNamedFunction(M, fnname):
+ # ../llvmcapi/include/VMCore/Module.h 15
+ return Module_getNamedFunction._api_(M, fnname)
+Module_getNamedFunction = cdecl(c_void_p, 'llvmcapi', [c_void_p, STRING]) (Module_getNamedFunction)
+
+
def Module_ParseAssemblyString(M, AsmString):
- # ../llvmcapi/include/VMCore/Module.h 19
+ # ../llvmcapi/include/VMCore/Module.h 18
return Module_ParseAssemblyString._api_(M, AsmString)
Module_ParseAssemblyString = cdecl(None, 'llvmcapi', [c_void_p, STRING]) (Module_ParseAssemblyString)
def Module_verifyModule(M):
- # ../llvmcapi/include/VMCore/Module.h 20
+ # ../llvmcapi/include/VMCore/Module.h 19
return Module_verifyModule._api_(M)
Module_verifyModule = cdecl(c_int, 'llvmcapi', [c_void_p]) (Module_verifyModule)
+def Module_n_functions(M):
+ # ../llvmcapi/include/VMCore/Module.h 22
+ return Module_n_functions._api_(M)
+Module_n_functions = cdecl(c_int, 'llvmcapi', [c_void_p]) (Module_n_functions)
+
+
+def Module_function_exists(M, fnname):
+ # ../llvmcapi/include/VMCore/Module.h 23
+ return Module_function_exists._api_(M, fnname)
+Module_function_exists = cdecl(c_int, 'llvmcapi', [c_void_p, STRING]) (Module_function_exists)
+
+
def ExistingModuleProvider__init__(M):
# ../llvmcapi/include/VMCore/ModuleProvider.h 8
return ExistingModuleProvider__init__._api_(M)
@@ -84,7 +144,7 @@
def toggle_print_machineinstrs():
- # ../llvmcapi/include/llvmcapi.h 13
+ # ../llvmcapi/include/llvmcapi.h 15
return toggle_print_machineinstrs._api_()
toggle_print_machineinstrs = cdecl(None, 'llvmcapi', []) (toggle_print_machineinstrs)
Modified: pypy/dist/pypy/translator/llvm/pythonllvm/pyllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/pythonllvm/pyllvm.py (original)
+++ pypy/dist/pypy/translator/llvm/pythonllvm/pyllvm.py Mon Apr 3 13:28:26 2006
@@ -1,29 +1,89 @@
from helper import *
+
class Module(Wrapper):
def __init__(self, ModuleID='mymodule'):
self.instance = Module__init__(ModuleID)
-class ModuleProvider(Wrapper):
- pass
+ def getNamedFunction(self, fnname):
+ f = object.__new__(Function)
+ f.instance = Module_getNamedFunction(self.instance, fnname)
+ return f
+
-class ExistingModuleProvider(ModuleProvider):
+class ExistingModuleProvider(Wrapper):
def __init__(self, M=None):
if not M:
M = Module()
self.instance = ExistingModuleProvider__init__(M.instance)
+global ee_hack
+
class ExecutionEngine(Wrapper):
def __init__(self, MP=None, ForceInterpreter=False):
if not MP:
MP = ExistingModuleProvider();
self.instance = ExecutionEngine__create__(MP.instance, ForceInterpreter)
+ global ee_hack
+ ee_hack = self.instance
+ # XXX cast to actual Python Module (can't we automate this?)
def getModule(self):
m = object.__new__(Module)
m.instance = ExecutionEngine_getModule(self.instance)
return m
+ # helpers
def parse(self, llcode):
- self.getModule().ParseAssemblyString(llcode)
- self.getModule().verifyModule()
+ mod = self.getModule()
+ mod.ParseAssemblyString(llcode)
+ mod.verifyModule()
+
+ def delete(self, fnname):
+ mod = self.getModule()
+ f = mod.getNamedFunction(fnname) # XXX handle fnname not found?
+ self.freeMachineCodeForFunction(f) # still no-op on march 27th 2006
+ f.eraseFromParent()
+
+
+def to_llvm_value(pythonvalue, type_):
+ # XXX use the GenericValue union instead
+ return pythonvalue
+
+
+def to_python_value(llvmvalue, type_):
+ # XXX use the GenericValue union instead
+ return llvmvalue
+
+
+class Function(Wrapper):
+ def __init__(self):
+ self.instance = Function__init__() #XXX this get annoying quickly
+
+ def __call__(self, *args):
+ print 'calling %s(%s)' % ('Function', ','.join([str(arg) for arg in args]))
+ ft = Function_getFunctionType(self.instance)
+ argcount = FunctionType_getNumParams(ft)
+ print 'argcount = ',argcount
+ if argcount != len(args):
+ raise Exception("incorrect number of parameters")
+ llvmvalues = GenericValue__init__()
+ for i, arg in enumerate(args):
+ llvmvalues.append( to_llvm_value(arg, FunctionType_getParamType(ft, i)))
+ llvmreturnvalue = ExecutionEngine_runFunction(ee_hack, self.instance, llvmvalues)
+ return to_python_value(llvmreturnvalue, FunctionType_getReturnType(ft))
+
+
+class GenericValue(Wrapper):
+ def __init(self):
+ self.instance = GenericValue__init__()
+
+
+#class Instruction(Wrapper):
+# def __init__(self):
+# self.instance = Instruction__init__()
+#
+#
+#class BasicBlock(Wrapper):
+# def __init__(self):
+# self.instance = BasicBlock__init__()
Modified: pypy/dist/pypy/translator/llvm/pythonllvm/test/test_ee.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/pythonllvm/test/test_ee.py (original)
+++ pypy/dist/pypy/translator/llvm/pythonllvm/test/test_ee.py Mon Apr 3 13:28:26 2006
@@ -27,7 +27,8 @@
def test_functions():
ee = pyllvm.ExecutionEngine()
ee.parse(codepath.join("hello.s").read())
- assert ee.n_functions() == 2
+ mod = ee.getModule()
+ assert mod.n_functions() == 2
#TODO
#for function in functions:
# returnId, name, args = function
@@ -35,27 +36,26 @@
# assert returnId > 0
# assert name in ('gethellostr', 'hello')
# assert len(args) == 0
- py.test.raises(Exception, ee.n_functions, 1)
- py.test.raises(Exception, ee.n_functions, "string")
+ py.test.raises(Exception, mod.n_functions, 1)
+ py.test.raises(Exception, mod.n_functions, "string")
def test_call_parse_once():
ee = pyllvm.ExecutionEngine()
ee.parse(codepath.join("hello.s").read())
- assert ee.call("hello") == 0
- assert ee.call("gethellostr") == "hello world\n"
- py.test.raises(Exception, ee.call)
- py.test.raises(Exception, ee.call, 1)
- py.test.raises(Exception, ee.call, "gethellostrx")
- py.test.raises(Exception, ee.call, "gethellostrx", 1)
- py.test.raises(Exception, ee.call, "gethellostr", 1)
+ f = ee.getModule().getNamedFunction
+ hello = f("hello")
+ gethellostr = f("gethellostr")
+ assert hello() == 0
+ assert gethellostr() == "hello world\n"
def test_call_parse_twice():
ee = pyllvm.ExecutionEngine()
ee.parse(codepath.join("hello.s").read())
- assert ee.call("gethellostr") == "hello world\n"
+ f = ee.getModule().getNamedFunction
+ assert f("gethellostr")() == "hello world\n"
ee.parse(codepath.join("addnumbers.s").read())
- assert ee.call("add", 10, 32) == 42
- assert ee.call("gethellostr") == "hello world\n"
+ assert f("add")(10, 32) == 42
+ assert f("gethellostr")() == "hello world\n"
py.test.raises(Exception, ee.parse)
py.test.raises(Exception, ee.parse, 1)
py.test.raises(Exception, ee.parse, "abc")
@@ -68,8 +68,9 @@
ee = pyllvm.ExecutionEngine()
ee.parse(ll_snippet.calc)
ee.parse(ll_snippet.add1)
- assert ee.call("add1", 41) == 42
- assert ee.call("calc", 122) == 123
+ f = ee.getModule().getNamedFunction
+ assert f("add1")(41) == 42
+ assert f("calc")(122) == 123
def test_replace_function():
"""similar to test_call_between_parsed_code with additional complexity
@@ -78,46 +79,51 @@
ee = pyllvm.ExecutionEngine()
ee.parse(ll_snippet.calc)
ee.parse(ll_snippet.add1)
- assert ee.call("add1", 41) == 42
- assert ee.call("calc", 122) == 123 #XXX need recompileAndRelinkFunction somewhere
+ f = ee.getModule().getNamedFunction
+ assert f("add1")(41) == 42
+ assert f("calc")(122) == 123 #XXX need recompileAndRelinkFunction somewhere
ee.parse(ll_snippet.add1_version2, "add1")
- assert ee.call("add1", 42) == 142
- assert ee.call("calc", 142) == 242
+ assert f("add1")(42) == 142
+ assert f("calc")(142) == 242
def test_share_data_between_parsed_code():
ee = pyllvm.ExecutionEngine()
ee.parse(ll_snippet.global_int_a_is_100)
ee.parse(ll_snippet.add1_to_global_int_a)
ee.parse(ll_snippet.sub10_from_global_int_a)
- assert ee.call("add1_to_global_int_a") == 101
- assert ee.call("sub10_from_global_int_a") == 91
- assert ee.call("add1_to_global_int_a") == 92
- assert ee.call("sub10_from_global_int_a") == 82
+ f = ee.getModule().getNamedFunction
+ assert f("add1_to_global_int_a")() == 101
+ assert f("sub10_from_global_int_a")() == 91
+ assert f("add1_to_global_int_a")() == 92
+ assert f("sub10_from_global_int_a")() == 82
def test_native_code(): #examine JIT generate native (assembly) code
pyllvm.toggle_print_machineinstrs()
ee = pyllvm.ExecutionEngine()
ee.parse(ll_snippet.calc)
ee.parse(ll_snippet.add1)
- assert ee.call("calc", 41) == 42
+ f = ee.getModule().getNamedFunction
+ assert f("calc")(41) == 42
pyllvm.toggle_print_machineinstrs()
def test_delete_function(): #this will only work if nothing uses Fn of course!
ee = pyllvm.ExecutionEngine()
+ mod = ee.getModule()
ee.parse(ll_snippet.calc)
ee.parse(ll_snippet.add1)
- assert ee.n_functions() == 2
+ assert mod.n_functions() == 2
ee.delete("calc")
- assert ee.n_functions() == 1
- assert ee.call("add1", 41) == 42
+ assert mod.n_functions() == 1
+ f = ee.getModule().getNamedFunction
+ assert f("add1")(41) == 42
ee.delete("add1")
- assert ee.n_functions() == 0
+ assert mod.n_functions() == 0
ee.parse(ll_snippet.calc)
ee.parse(ll_snippet.add1)
- assert ee.call("calc", 100) == 101
+ assert f("calc")(100) == 101
def TODOtest_add_to_function():
pass
More information about the Pypy-commit
mailing list