[pypy-svn] r51240 - in pypy/dist/pypy: jit/codegen/cli jit/codegen/cli/test jit/codegen/test translator/cli translator/cli/test
antocuni at codespeak.net
antocuni at codespeak.net
Mon Feb 4 10:52:37 CET 2008
Author: antocuni
Date: Mon Feb 4 10:52:37 2008
New Revision: 51240
Added:
pypy/dist/pypy/jit/codegen/cli/
pypy/dist/pypy/jit/codegen/cli/__init__.py (contents, props changed)
pypy/dist/pypy/jit/codegen/cli/rgenop.py (contents, props changed)
pypy/dist/pypy/jit/codegen/cli/test/
pypy/dist/pypy/jit/codegen/cli/test/test_rgenop.py (contents, props changed)
Modified:
pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
pypy/dist/pypy/translator/cli/opcodes.py
pypy/dist/pypy/translator/cli/test/runtest.py
Log:
first draft of the CLI backend for the JIT.
Tests are disabled, since only test_adder_direct and
test_adder_compile pass.
Added: pypy/dist/pypy/jit/codegen/cli/__init__.py
==============================================================================
Added: pypy/dist/pypy/jit/codegen/cli/rgenop.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/cli/rgenop.py Mon Feb 4 10:52:37 2008
@@ -0,0 +1,152 @@
+from pypy.tool.pairtype import extendabletype
+from pypy.rpython.ootypesystem import ootype
+from pypy.rlib.objectmodel import specialize
+from pypy.jit.codegen.model import AbstractRGenOp, GenLabel, GenBuilder
+from pypy.jit.codegen.model import GenVarOrConst, GenVar, GenConst, CodeGenSwitch
+from pypy.translator.cli.dotnet import CLR, typeof, new_array, clidowncast
+System = CLR.System
+Utils = CLR.pypy.runtime.Utils
+OpCodes = System.Reflection.Emit.OpCodes
+
+def token2clitype(tok):
+ if tok == '<Signed>':
+ return typeof(System.Int32)
+ else:
+ assert False
+
+class __extend__(GenVarOrConst):
+ __metaclass__ = extendabletype
+
+ def load(self, il):
+ raise NotImplementedError
+
+ def store(self, il):
+ raise NotImplementedError
+
+class GenArgVar(GenVar):
+ def __init__(self, index):
+ self.index = index
+ # XXX maybe we need to store also the type?
+
+ def load(self, il):
+ if self.index == 0:
+ il.Emit(OpCodes.Ldarg_0)
+ elif self.index == 1:
+ il.Emit(OpCodes.Ldarg_1)
+ elif self.index == 2:
+ il.Emit(OpCodes.Ldarg_2)
+ elif self.index == 3:
+ il.Emit(OpCodes.Ldarg_3)
+ else:
+ il.Emit(OpCodes.Ldarg, self.index)
+
+ def store(self, il):
+ il.Emit(OpCodes.Starg, self.index)
+
+ def __repr__(self):
+ return "GenArgVar(%d)" % self.index
+
+class GenLocalVar(GenVar):
+ def __init__(self, v):
+ self.v = v
+
+ def load(self, il):
+ il.Emit(OpCodes.Ldloc, self.v)
+
+ def store(self, il):
+ il.Emit(OpCodes.Stloc, self.v)
+
+class IntConst(GenConst):
+
+ def __init__(self, value):
+ self.value = value
+
+ @specialize.arg(1)
+ def revealconst(self, T):
+ assert T is ootype.Signed
+ return self.value
+
+ def load(self, il):
+ il.Emit(OpCodes.Ldc_I4, self.value)
+
+ def __repr__(self):
+ "NOT_RPYTHON"
+ return "const=%s" % self.value
+
+class ObjectConst(GenConst):
+
+ def __init__(self, obj):
+ self.obj = obj
+
+ @specialize.arg(1)
+ def revealconst(self, T):
+ DelegateType = CLR.pypy.runtime.DelegateType_int__int # XXX use T
+ return clidowncast(DelegateType, self.obj)
+
+
+class RCliGenOp(AbstractRGenOp):
+
+ def __init__(self):
+ self.meth = None
+ self.il = None
+
+ @specialize.genconst(1)
+ def genconst(self, llvalue):
+ T = ootype.typeOf(llvalue)
+ if T is ootype.Signed:
+ return IntConst(llvalue)
+ else:
+ assert False, "XXX not implemented"
+
+ @staticmethod
+ @specialize.memo()
+ def sigToken(FUNCTYPE):
+ """Return a token describing the signature of FUNCTYPE."""
+ # XXX: the right thing to do would be to have a way to
+ # represent typeof(t) as a pbc
+ args = [repr(T) for T in FUNCTYPE.ARGS]
+ res = repr(FUNCTYPE.RESULT)
+ return args, res
+
+ def newgraph(self, sigtoken, name):
+ argtoks, restok = sigtoken
+ args = new_array(System.Type, len(argtoks))
+ for i in range(len(argtoks)):
+ args[i] = token2clitype(argtoks[i])
+ res = token2clitype(restok)
+ builder = Builder(self, name, res, args)
+ return builder, builder.gv_entrypoint, builder.inputargs_gv[:]
+
+
+
+class Builder(GenBuilder):
+
+ def __init__(self, rgenop, name, res, args):
+ self.rgenop = rgenop
+ self.meth = Utils.CreateDynamicMethod(name, res, args)
+ self.il = self.meth.GetILGenerator()
+ self.inputargs_gv = []
+ for i in range(len(args)):
+ self.inputargs_gv.append(GenArgVar(i))
+ self.gv_entrypoint = ObjectConst(None) # XXX?
+
+ @specialize.arg(1)
+ def genop2(self, opname, gv_arg1, gv_arg2):
+ assert opname == 'int_add'
+ res = self.il.DeclareLocal(typeof(System.Int32))
+ gv_res = GenLocalVar(res)
+ gv_arg1.load(self.il)
+ gv_arg2.load(self.il)
+ self.il.Emit(OpCodes.Add)
+ gv_res.store(self.il)
+ return gv_res
+
+ def finish_and_return(self, sigtoken, gv_returnvar):
+ gv_returnvar.load(self.il)
+ self.il.Emit(OpCodes.Ret)
+ DelegateType = CLR.pypy.runtime.DelegateType_int__int # XXX use sigtoken
+ myfunc = self.meth.CreateDelegate(typeof(DelegateType))
+ self.gv_entrypoint.obj = myfunc
+
+ def end(self):
+ pass
Added: pypy/dist/pypy/jit/codegen/cli/test/test_rgenop.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/cli/test/test_rgenop.py Mon Feb 4 10:52:37 2008
@@ -0,0 +1,28 @@
+import py
+from pypy.rpython.ootypesystem import ootype
+from pypy.jit.codegen.cli.rgenop import RCliGenOp
+from pypy.jit.codegen.test.rgenop_tests import AbstractRGenOpTests, OOType
+from pypy.translator.cli.test.runtest import compile_function
+
+# test disabled, only two pass
+class xTestRCliGenop(AbstractRGenOpTests):
+ RGenOp = RCliGenOp
+ T = OOType
+
+ # for the individual tests see
+ # ====> ../../test/rgenop_tests.py
+
+ def getcompiled(self, fn, annotation, annotatorpolicy):
+ return compile_function(fn, annotation,
+ annotatorpolicy=annotatorpolicy,
+ nowrap=True)
+
+ def cast(self, gv, nb_args):
+ "NOT_RPYTHON"
+ def fn(*args):
+ return gv.obj.Invoke(*args)
+ return fn
+
+ def directtesthelper(self, FUNCTYPE, func):
+ py.test.skip('???')
+
Modified: pypy/dist/pypy/jit/codegen/test/rgenop_tests.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/test/rgenop_tests.py (original)
+++ pypy/dist/pypy/jit/codegen/test/rgenop_tests.py Mon Feb 4 10:52:37 2008
@@ -3,6 +3,7 @@
from pypy.rlib.rarithmetic import intmask, r_uint
from pypy.rlib.objectmodel import keepalive_until_here
from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rpython.ootypesystem import ootype
from pypy.translator.c.test import test_boehm
from ctypes import c_void_p, cast, CFUNCTYPE, c_int
@@ -21,7 +22,20 @@
@staticmethod
def Ptr(FUNC):
return lltype.Ptr(FUNC)
-
+
+
+class OOType(object):
+ FUNC = ootype.StaticMethod([lltype.Signed], lltype.Signed)
+ FUNC2 = ootype.StaticMethod([lltype.Signed]*2, lltype.Signed)
+ FUNC3 = ootype.StaticMethod([lltype.Signed]*3, lltype.Signed)
+ FUNC5 = ootype.StaticMethod([lltype.Signed]*5, lltype.Signed)
+ FUNC27= ootype.StaticMethod([lltype.Signed]*27, lltype.Signed)
+ FUNC100 = ootype.StaticMethod([lltype.Signed]*100, lltype.Signed)
+
+ @staticmethod
+ def Ptr(FUNC):
+ return FUNC
+
def make_adder(T, rgenop, n):
# 'return x+n'
Modified: pypy/dist/pypy/translator/cli/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/cli/opcodes.py (original)
+++ pypy/dist/pypy/translator/cli/opcodes.py Mon Feb 4 10:52:37 2008
@@ -67,6 +67,7 @@
'gc_set_max_heap_size': Ignore,
'resume_point': Ignore,
'debug_assert': Ignore,
+ 'keepalive': Ignore,
# __________ numeric operations __________
Modified: pypy/dist/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/runtest.py (original)
+++ pypy/dist/pypy/translator/cli/test/runtest.py Mon Feb 4 10:52:37 2008
@@ -136,15 +136,17 @@
def compile_function(func, annotation=[], graph=None, backendopt=True,
- auto_raise_exc=False, exctrans=False):
+ auto_raise_exc=False, exctrans=False,
+ annotatorpolicy=None, nowrap=False):
olddefs = patch_os()
- gen = _build_gen(func, annotation, graph, backendopt, exctrans)
+ gen = _build_gen(func, annotation, graph, backendopt, exctrans, annotatorpolicy, nowrap)
gen.generate_source()
exe_name = gen.build_exe()
unpatch_os(olddefs) # restore original values
return CliFunctionWrapper(exe_name, func.__name__, auto_raise_exc)
-def _build_gen(func, annotation, graph=None, backendopt=True, exctrans=False):
+def _build_gen(func, annotation, graph=None, backendopt=True, exctrans=False,
+ annotatorpolicy=None, nowrap=False):
try:
func = func.im_func
except AttributeError:
@@ -152,12 +154,12 @@
t = TranslationContext()
if graph is not None:
graph.func = func
- ann = t.buildannotator()
+ ann = t.buildannotator(policy=annotatorpolicy)
inputcells = [ann.typeannotation(a) for a in annotation]
ann.build_graph_types(graph, inputcells)
t.graphs.insert(0, graph)
else:
- ann = t.buildannotator()
+ ann = t.buildannotator(policy=annotatorpolicy)
ann.build_types(func, annotation)
if getoption('view'):
@@ -178,7 +180,7 @@
else:
tmpdir = udir
- return GenCli(tmpdir, t, TestEntryPoint(main_graph, True), exctrans=exctrans)
+ return GenCli(tmpdir, t, TestEntryPoint(main_graph, not nowrap), exctrans=exctrans)
class CliFunctionWrapper(object):
def __init__(self, exe_name, name=None, auto_raise_exc=False):
More information about the Pypy-commit
mailing list