[pypy-commit] pypy stm: stm_getfield in genc.
arigo
noreply at buildbot.pypy.org
Tue Sep 27 15:24:10 CEST 2011
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r47627:7812e44b10c5
Date: 2011-09-27 15:23 +0200
http://bitbucket.org/pypy/pypy/changeset/7812e44b10c5/
Log: stm_getfield in genc.
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -589,6 +589,22 @@
return '%s = %s.length;'%(self.expr(op.result), expr)
+ def OP_STM_GETFIELD(self, op):
+ assert isinstance(op.args[1], Constant)
+ STRUCT = self.lltypemap(op.args[0]).TO
+ structdef = self.db.gettypedefnode(STRUCT)
+ baseexpr_is_const = isinstance(op.args[0], Constant)
+ sourceexpr = structdef.ptr_access_expr(self.expr(op.args[0]),
+ op.args[1].value,
+ baseexpr_is_const)
+ #
+ T = self.lltypemap(op.result)
+ assert T is not Void
+ typename = self.db.gettype(T)
+ newvalue = self.expr(op.result)
+ return '%s = (%s)stm_read_word((void**)&%s);' % (
+ newvalue, cdecl(typename, ''), sourceexpr)
+
def OP_PTR_NONZERO(self, op):
return '%s = (%s != NULL);' % (self.expr(op.result),
diff --git a/pypy/translator/stm/rstm.py b/pypy/translator/stm/rstm.py
--- a/pypy/translator/stm/rstm.py
+++ b/pypy/translator/stm/rstm.py
@@ -1,5 +1,8 @@
from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.translator.stm import _rffi_stm
+from pypy.annotation import model as annmodel
+from pypy.objspace.flow.model import Constant
def stm_getfield(structptr, fieldname):
@@ -13,3 +16,20 @@
p = rffi.cast(rffi.VOIDPP, p)
pval = rffi.cast(rffi.VOIDP, newvalue)
_rffi_stm.stm_write_word(p, pval)
+
+
+# ____________________________________________________________
+
+class ExtEntry(ExtRegistryEntry):
+ _about_ = stm_getfield
+
+ def compute_result_annotation(self, s_structptr, s_fieldname):
+ return annmodel.SomeInteger()
+
+ def specialize_call(self, hop):
+ r_structptr = hop.args_r[0]
+ v_structptr = hop.inputarg(r_structptr, arg=0)
+ fieldname = hop.args_v[1].value
+ c_fieldname = hop.inputconst(lltype.Void, fieldname)
+ return hop.genop('stm_getfield', [v_structptr, c_fieldname],
+ resulttype = lltype.Signed)
More information about the pypy-commit
mailing list