[pypy-svn] r13579 - pypy/dist/pypy/translator/llvm2

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Jun 18 12:06:14 CEST 2005


Author: cfbolz
Date: Sat Jun 18 12:06:14 2005
New Revision: 13579

Modified:
   pypy/dist/pypy/translator/llvm2/funcgen.py
   pypy/dist/pypy/translator/llvm2/genllvm.py
Log:
new llvm passes first trivial test:
generation of Pyrex wrapper works


Modified: pypy/dist/pypy/translator/llvm2/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/funcgen.py	(original)
+++ pypy/dist/pypy/translator/llvm2/funcgen.py	Sat Jun 18 12:06:14 2005
@@ -5,6 +5,7 @@
 
 
 PRIMITIVES_TO_LLVM = {lltype.Signed: "int"}
+PRIMITIVES_TO_C = {lltype.Signed: "int"}
 
 log = py.log.Producer('genllvm') 
 
@@ -12,16 +13,34 @@
     def __init__(self, graph, func):
         self.graph = graph
         self.func = func
+        self.funcname = self.func.func_name
 
     def declaration(self):
-        returntype = self.getllvmname(self.graph.returnblock.inputargs[0])
-        argtypes = self.getllvmtypes(self.graph.startblock.inputargs)
-        funcname = "%" + self.func.func_name
-   # XXX varnames
-        result = "%s %s(%s)" % (returntype, funcname,
-                                ", ".join(argtypes))
+        startblock = self.graph.startblock
+        returnblock = self.graph.returnblock
+        inputargs = self.getllvmnames(startblock.inputargs)
+        inputargtypes = self.getllvmtypes(startblock.inputargs)
+        returntype = self.getllvmtype(self.graph.returnblock.inputargs[0])
+        result = "%s %%%s" % (returntype, self.funcname)
+        args = ["%s %s" % item for item in zip(inputargs, inputargtypes)]
+        result += "(%s)" % ", ".join(args)
         return result
 
+    def c_declaration(self):
+        returntype = PRIMITIVES_TO_C[
+            self.graph.returnblock.inputargs[0].concretetype]
+        inputargtypes = [PRIMITIVES_TO_C[arg.concretetype]
+                             for arg in self.graph.startblock.inputargs]
+        result = "%s %s(%s)" % (returntype, self.funcname,
+                                ", ".join(inputargtypes))
+        return result
+
+    def pyrex_wrapper(self):
+        inputargs = self.getllvmnames(self.graph.startblock.inputargs)
+        yield "cdef extern " + self.c_declaration()
+        yield "def %s_wrapper(%s):" % (self.funcname, ", ".join(inputargs))
+        yield "    return %s(%s)" % (self.funcname, ", ".join(inputargs))
+
     def implementation(self):
         graph = self.graph
         log.gen("starting", graph.name)

Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py	Sat Jun 18 12:06:14 2005
@@ -8,18 +8,18 @@
     graph = translator.getflowgraph(func)
     targetdir = udir
     funcgen = FunctionCodeGenerator(graph, func)
-    llvmfile = targetdir.join("f.ll")
-    pyxfile = targetdir.join("f.pyx")
-    f = llvmfile.open("w")
+    llvmsource = targetdir.join(func.func_name).new(ext='.ll')
+    pyxsource = llvmsource.new(basename=llvmsource.purebasename+'_wrapper'+'.pyx')
+    f = llvmsource.open("w")
     print >> f, funcgen.declaration()
     print >> f, "{"
     for line in funcgen.implementation():
         print >> f, line
     print >> f, "}"
     f.close()
-    f = pyxfile.open("w")
-    py.test.skip("no pyrex wrapping support, check back tomorrow") 
+    f = pyxsource.open("w")
     for line in funcgen.pyrex_wrapper():
         print >> f, line
     f.close()
-    return build_llvm_module.make_module_from_llvm(llvmfile, pyxfile)
+    mod = build_llvm_module.make_module_from_llvm(llvmsource, pyxsource)
+    return getattr(mod, func.func_name + "_wrapper")



More information about the Pypy-commit mailing list