[pypy-svn] r18449 - in pypy/dist/pypy/translator/llvm: . module

ericvrp at codespeak.net ericvrp at codespeak.net
Wed Oct 12 11:49:18 CEST 2005


Author: ericvrp
Date: Wed Oct 12 11:49:16 2005
New Revision: 18449

Modified:
   pypy/dist/pypy/translator/llvm/build_llvm_module.py
   pypy/dist/pypy/translator/llvm/externs2ll.py
   pypy/dist/pypy/translator/llvm/gc.py
   pypy/dist/pypy/translator/llvm/module/genexterns.c
Log:
some code to make this compile on OSX

Modified: pypy/dist/pypy/translator/llvm/build_llvm_module.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/build_llvm_module.py	(original)
+++ pypy/dist/pypy/translator/llvm/build_llvm_module.py	Wed Oct 12 11:49:16 2005
@@ -82,13 +82,19 @@
 
     use_gcc = True
     profile = False
+    cleanup = False
+
+    if sys.platform == 'darwin':
+        gc_libs_path = '-L/sw/lib -ldl'
+    else:
+        gc_libs_path = '-static'
 
     cmds = ["llvm-as < %s.ll | opt %s -f -o %s.bc" % (b, OPTIMIZATION_SWITCHES, b)]
     if not use_gcc:
         cmds.append("llc %s %s.bc -f -o %s.s" % (genllvm.exceptionpolicy.llc_options(), b, b))
         cmds.append("as %s.s -o %s.o" % (b, b))
         if exe_name:
-            cmd = "gcc %s.o %s -lm -ldl -pipe -o %s" % (b, gc_libs, exe_name)
+            cmd = "gcc %s.o %s %s -lm -pipe -o %s" % (b, gc_libs_path, gc_libs, exe_name)
             cmds.append(cmd)
         object_files.append("%s.o" % b)
     else:
@@ -100,13 +106,13 @@
             else:
                 cmd += ' -fomit-frame-pointer'
             cmds.append(cmd)
-            cmd = "gcc %s.o %s -lm -ldl -pipe -o %s" % (b, gc_libs, exe_name)
+            cmd = "gcc %s.o %s %s -lm -pipe -o %s" % (b, gc_libs_path, gc_libs, exe_name)
             if profile:
                 cmd += ' -pg'
             cmds.append(cmd)
         source_files.append("%s.c" % b)
 
-    if exe_name and not profile:
+    if cleanup and exe_name and not profile:
         cmds.append('strip ' + exe_name)
         upx = os.popen('which upx').read()
         if upx: #compress file even further

Modified: pypy/dist/pypy/translator/llvm/externs2ll.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/externs2ll.py	(original)
+++ pypy/dist/pypy/translator/llvm/externs2ll.py	Wed Oct 12 11:49:16 2005
@@ -1,4 +1,5 @@
 import os
+import sys
 import types
 import urllib
 
@@ -11,10 +12,20 @@
 
 
 def get_ll(ccode, function_names):
+    filename = str(udir.join("ccode.c"))
+    f = open(filename, "w")
+    f.write(ccode)
+    f.close()
     
-    # goto codespeak and compile our c code
-    request = urllib.urlencode({'ccode':ccode})
-    llcode = urllib.urlopen('http://codespeak.net/pypy/llvm-gcc.cgi', request).read()
+    if os.popen('which llvm-gcc').read():   #local llvm CFE available
+        #log('using local llvm-gcc')
+        plain = filename[:-2]
+        os.system("llvm-gcc -S %s.c -o %s.ll 2>&1" % (plain, plain))
+        llcode = open(plain + '.ll').read()
+    else:   #as fallback use remove CFE. XXX local and remote should be similar machines!
+        #log('falling back on remote llvm-gcc')
+        request = urllib.urlencode({'ccode':ccode}) # goto codespeak and compile our c code
+        llcode = urllib.urlopen('http://codespeak.net/pypy/llvm-gcc.cgi', request).read()
 
     # strip lines
     ll_lines = []
@@ -134,13 +145,14 @@
         include_files.append(j(j(os.path.dirname(extfunc.__file__), "src"), f + ".h"))
 
     for f in include_files:
-        ccode.append(open(f).read())
+        s = open(f).read()
+        if f.find('genexterns.c'):
+            if sys.platform == 'darwin':
+                python_h = '"/System/Library/Frameworks/Python.framework/Versions/2.3/include/python2.3/Python.h"'
+            else:
+                python_h = '<python2.3/Python.h>'
+            s = s.replace('__PYTHON_H__', python_h)
+        ccode.append(s)
     ccode = "".join(ccode)
 
-    if debug:
-        filename = udir.join("ccode.c")
-        f = open(str(filename), "w")
-        f.write(ccode)
-        f.close()
-    
     return get_ll(ccode, function_names + support_functions)

Modified: pypy/dist/pypy/translator/llvm/gc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/gc.py	(original)
+++ pypy/dist/pypy/translator/llvm/gc.py	Wed Oct 12 11:49:16 2005
@@ -25,7 +25,8 @@
         gcpolicy = gcpolicy or 'boehm'
         
         from os.path import exists
-        boehm_on_path = exists('/usr/lib/libgc.so') or exists('/usr/lib/libgc.a')
+        boehm_on_path = exists('/usr/lib/libgc.so') or exists('/usr/lib/libgc.a') or \
+                        exists('/sw/lib/libgc.so') or exists('/sw/lib/libgc.a')
         if gcpolicy == 'boehm' and not boehm_on_path:
             log.gc.WARNING('warning: Boehm GC libary not found in /usr/lib, falling back on no gc')
             gcpolicy = 'none'

Modified: pypy/dist/pypy/translator/llvm/module/genexterns.c
==============================================================================
--- pypy/dist/pypy/translator/llvm/module/genexterns.c	(original)
+++ pypy/dist/pypy/translator/llvm/module/genexterns.c	Wed Oct 12 11:49:16 2005
@@ -19,7 +19,9 @@
 #include <errno.h>
 #include <locale.h>
 #include <ctype.h>
-#include <python2.3/Python.h>
+
+//the placeholder in the next line gets replaced by the actual python.h path
+#include __PYTHON_H__
 
 // Do this manually from python :-(
 //#include "ll_os.h"



More information about the Pypy-commit mailing list