[pypy-svn] r14288 - in pypy/dist/pypy/translator/llvm2: . test
hpk at codespeak.net
hpk at codespeak.net
Tue Jul 5 15:38:51 CEST 2005
Author: hpk
Date: Tue Jul 5 15:38:49 2005
New Revision: 14288
Modified:
pypy/dist/pypy/translator/llvm2/arraynode.py
pypy/dist/pypy/translator/llvm2/funcnode.py
pypy/dist/pypy/translator/llvm2/structnode.py
pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
Log:
(rxe, hpk)
- refactoring the array constructor to also serve
for constructring varsize arrays
- clean up little bits and pieces
Modified: pypy/dist/pypy/translator/llvm2/arraynode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/arraynode.py (original)
+++ pypy/dist/pypy/translator/llvm2/arraynode.py Tue Jul 5 15:38:49 2005
@@ -3,6 +3,7 @@
from pypy.translator.llvm2.log import log
from pypy.translator.llvm2.node import LLVMNode
from pypy.objspace.flow.model import Constant
+from pypy.translator.llvm2 import varsize
import itertools
log = log.structnode
@@ -35,34 +36,11 @@
codewriter.declare(self.constructor_decl)
def writeimpl(self, codewriter):
- """ this function generates a LLVM function like the following:
- %array = type { int, [0 x double] }
- %array *%NewArray(int %len) {
- ;; Get the offset of the 'len' element of the array from the null
- ;; pointer.
- %size = getelementptr %array* null, int 0, uint 1, %int %len
- %usize = cast double* %size to uint
- %ptr = malloc sbyte, uint %usize
- %result = cast sbyte* %ptr to %array*
- %arraylength = getelementptr %array* %result, int 0, uint 0
- store int %len, int* %arraylength
- ret %array* %result
- }"""
- from pypy.translator.llvm2.atomic import is_atomic
-
log.writeimpl(self.ref)
- codewriter.openfunc(self.constructor_decl)
- indices = [("uint", 1), ("int", "%len")]
- codewriter.getelementptr("%size", self.ref + "*",
- "null", *indices)
fromtype = self.db.repr_arg_type(self.array.OF)
- codewriter.cast("%usize", fromtype + "*", "%size", "uint")
- codewriter.malloc("%ptr", "sbyte", "%usize", atomic=is_atomic(self))
- codewriter.cast("%result", "sbyte*", "%ptr", self.ref+"*")
- codewriter.getelementptr("%arraylength", self.ref+"*", "%result", ("uint", 0))
- codewriter.store("int", "%len", "%arraylength")
- codewriter.ret(self.ref+"*", "%result")
- codewriter.closefunc()
+ varsize.write_constructor(codewriter, self.ref,
+ self.constructor_decl,
+ fromtype)
def setup(self):
self.db.prepare_repr_arg_type(self.array.OF)
@@ -79,15 +57,11 @@
class ArrayNode(LLVMNode):
_issetup = False
- array_counter = 0
def __init__(self, db, value):
self.db = db
- name = '"%%arrayinstance.%s.%s"' % (
- value._TYPE.OF, ArrayNode.array_counter)
- self.ref = name
+ self.ref = "%%arrayinstance.%s.%s" % (value._TYPE.OF, nextnum())
self.value = value
- ArrayNode.array_counter += 1
def __str__(self):
return "<ArrayNode %r>" %(self.ref,)
Modified: pypy/dist/pypy/translator/llvm2/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcnode.py (original)
+++ pypy/dist/pypy/translator/llvm2/funcnode.py Tue Jul 5 15:38:49 2005
@@ -7,19 +7,16 @@
from pypy.translator.llvm2.node import LLVMNode
from pypy.translator.llvm2.atomic import is_atomic
from pypy.translator.llvm2.log import log
+nextnum = py.std.itertools.count().next
log = log.funcnode
class FuncTypeNode(LLVMNode):
- func_type_node_counter = 0
-
def __init__(self, db, type_):
self.db = db
assert isinstance(type_, lltype.FuncType)
self.type_ = type_
- ref = '"ft.%s.%s"' % (type_, FuncTypeNode.func_type_node_counter)
- self.ref = ref.replace(" ", "")
- FuncTypeNode.func_type_node_counter += 1
+ self.ref = 'ft.%s.%s' % (type_, nextnum())
def __str__(self):
return "<FuncTypeNode %r>" % self.ref
@@ -260,7 +257,7 @@
targetvar = self.db.repr_arg(op.result)
arg_type = op.args[0]
assert (isinstance(arg_type, Constant) and
- isinstance(arg_type.value, lltype.Array))
+ isinstance(arg_type.value, (lltype.Array, lltype.Struct)))
#XXX unclean
struct_type = self.db.obj2node[arg_type.value].ref
struct_cons = self.db.obj2node[arg_type.value].constructor_ref
Modified: pypy/dist/pypy/translator/llvm2/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/structnode.py (original)
+++ pypy/dist/pypy/translator/llvm2/structnode.py Tue Jul 5 15:38:49 2005
@@ -41,7 +41,13 @@
def __init__(self, db, struct):
super(StructVarsizeTypeNode, self).__init__(db, struct)
new_var_name = "%%new.st.var.%s" % self.name
- self.constructor_name = "%s * %s(int %%len)" % (self.ref, new_var_name)
+ self.constructor_ref = "%s * %s(int %%len)" % (self.ref, new_var_name)
+
+ ref_template = wrapstr("%%st.%s." + str(c))
+ self.ref = ref_template % array.OF
+ self.constructor_ref = wrapstr("%%new.array.%s" % c)
+ self.constructor_decl = "%s * %s(int %%len)" % \
+ (self.ref, self.constructor_ref)
def __str__(self):
return "<StructVarsizeTypeNode %r>" %(self.ref,)
Modified: pypy/dist/pypy/translator/llvm2/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm2/test/test_genllvm.py Tue Jul 5 15:38:49 2005
@@ -314,6 +314,12 @@
for j in range(6):
assert f(i,j) == list_basic_ops(i,j)
+def xtest_string_simple():
+ def string_simple(i):
+ return str(i)
+ f = compile_function(string_simple, [int], view=False)
+ assert f(0)
+
def Xtest_string_getitem1():
l = "Hello, World"
def string_getitem1(i):
More information about the Pypy-commit
mailing list