[pypy-svn] r17399 - pypy/dist/pypy/translator/llvm
ericvrp at codespeak.net
ericvrp at codespeak.net
Fri Sep 9 10:58:49 CEST 2005
Author: ericvrp
Date: Fri Sep 9 10:58:48 2005
New Revision: 17399
Modified:
pypy/dist/pypy/translator/llvm/exception.py
pypy/dist/pypy/translator/llvm/genllvm.py
Log:
Refactored pyrex (module) entry function out to the exception policy.
Modified: pypy/dist/pypy/translator/llvm/exception.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/exception.py (original)
+++ pypy/dist/pypy/translator/llvm/exception.py Fri Sep 9 10:58:48 2005
@@ -1,7 +1,13 @@
+from pypy.translator.llvm.codewriter import DEFAULT_CCONV
+
+
class ExceptionPolicy:
def __init__(self):
raise Exception, 'ExceptionPolicy should not be used directly'
+ def pyrex_entrypoint_code(self, entrynode):
+ return ''
+
def llc_options(self):
return ''
@@ -30,6 +36,34 @@
def __init__(self):
pass
+ def pyrex_entrypoint_code(self, entrynode):
+ returntype, entrypointname = entrynode.getdecl().split('%', 1)
+ if returntype == 'double ':
+ noresult = '0.0'
+ elif returntype == 'bool ':
+ noresult = 'false'
+ else:
+ noresult = '0'
+ cconv = DEFAULT_CCONV
+ return '''
+ccc %(returntype)s%%__entrypoint__%(entrypointname)s {
+ %%result = invoke %(cconv)s %(returntype)s%%%(entrypointname)s to label %%no_exception except label %%exception
+
+no_exception:
+ store %%RPYTHON_EXCEPTION_VTABLE* null, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
+ ret %(returntype)s %%result
+
+exception:
+ ret %(returntype)s %(noresult)s
+}
+
+ccc int %%__entrypoint__raised_LLVMException() {
+ %%tmp = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
+ %%result = cast %%RPYTHON_EXCEPTION_VTABLE* %%tmp to int
+ ret int %%result
+}
+''' % locals()
+
def llc_options(self):
return '-enable-correct-eh-support'
@@ -38,5 +72,5 @@
def __init__(self):
pass
- def llc_options(self):
- return '-enable-correct-eh-support'
+ pyrex_entrypoint_code = CPythonExceptionPolicy.pyrex_entrypoint_code
+ llc_options = CPythonExceptionPolicy.llc_options
Modified: pypy/dist/pypy/translator/llvm/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm/genllvm.py Fri Sep 9 10:58:48 2005
@@ -154,8 +154,7 @@
if using_external_functions:
nl(); comment("External Function Declarations") ; nl()
- for s in llexterns_header.split('\n'):
- codewriter.append(s)
+ codewriter.append(llexterns_header)
nl(); comment("Type Declarations"); nl()
for c_name, obj in extern_decls:
@@ -176,8 +175,8 @@
self._checkpoint('write global constants')
nl(); comment("Function Prototypes") ; nl()
- for extdecl in (extdeclarations+self.gcpolicy.declarations()).split('\n'):
- codewriter.append(extdecl)
+ codewriter.append(extdeclarations)
+ codewriter.append(self.gcpolicy.declarations())
self._checkpoint('write function prototypes')
for typ_decl in self.db.getnodes():
@@ -191,35 +190,11 @@
typ_decl.writeimpl(codewriter)
self._checkpoint('write implementations')
- #XXX use codewriter methods here
- decl = self.entrynode.getdecl()
- t = decl.split('%', 1)
- if t[0] == 'double ': #XXX I know, I know... refactor at will!
- no_result = '0.0'
- elif t[0] == 'bool ':
- no_result = 'false'
- else:
- no_result = '0'
- codewriter.newline()
- codewriter.append("ccc %s%%__entrypoint__%s {" % (t[0], t[1]))
- codewriter.append(" %%result = invoke %s %s%%%s to label %%no_exception except label %%exception" % (DEFAULT_CCONV, t[0], t[1]))
- codewriter.newline()
- codewriter.append("no_exception:")
- codewriter.append(" store %RPYTHON_EXCEPTION_VTABLE* null, %RPYTHON_EXCEPTION_VTABLE** %last_exception_type")
- codewriter.append(" ret %s%%result" % t[0])
- codewriter.newline()
- codewriter.append("exception:")
- codewriter.append(" ret %s%s" % (t[0], no_result))
- codewriter.append("}")
- codewriter.newline()
- codewriter.append("ccc int %__entrypoint__raised_LLVMException() {")
- codewriter.append(" %tmp = load %RPYTHON_EXCEPTION_VTABLE** %last_exception_type")
- codewriter.append(" %result = cast %RPYTHON_EXCEPTION_VTABLE* %tmp to int")
- codewriter.append(" ret int %result")
- codewriter.append("}")
- codewriter.newline()
+ codewriter.append(self.exceptionpolicy.pyrex_entrypoint_code(self.entrynode))
# XXX we need to create our own main() that calls the actual entry_point function
+ decl = self.entrynode.getdecl()
+ t = decl.split('%', 1)
entryfunc_name = t[1].split('(')[0]
if entryfunc_name == 'pypy_entry_point': #XXX just to get on with translate_pypy
extfuncnode.ExternalFuncNode.used_external_functions['%main'] = True
@@ -236,19 +211,14 @@
deps.reverse()
for dep in deps:
if dep not in depdone:
- try:
- llvm_code = extfunctions[dep][1]
- except KeyError: #external function that is shared with genc
- continue
- for extfunc in llvm_code.split('\n'):
- codewriter.append(extfunc)
+ if dep in extfunctions: #else external function that is shared with genc
+ codewriter.append(extfunctions[dep][1])
depdone[dep] = True
self._checkpoint('write support functions')
if using_external_functions:
nl(); comment("External Function Implementation") ; nl()
- for s in llexterns_functions.split('\n'):
- codewriter.append(s)
+ codewriter.append(llexterns_functions)
self._checkpoint('write external functions')
comment("End of file") ; nl()
@@ -274,8 +244,6 @@
pyxfile=pyxfile,
optimize=optimize)
- def _debug_prototype(self, codewriter):
- codewriter.append("declare int %printf(sbyte*, ...)")
def genllvm(translator, gcpolicy=None, exceptionpolicy=None, log_source=False, **kwds):
gen = GenLLVM(translator, GcPolicy.new(gcpolicy), ExceptionPolicy.new(exceptionpolicy))
More information about the Pypy-commit
mailing list