[pypy-svn] r18263 - pypy/dist/pypy/translator/js
ericvrp at codespeak.net
ericvrp at codespeak.net
Fri Oct 7 17:32:12 CEST 2005
Author: ericvrp
Date: Fri Oct 7 17:32:10 2005
New Revision: 18263
Modified:
pypy/dist/pypy/translator/js/arraynode.py
pypy/dist/pypy/translator/js/codewriter.py
pypy/dist/pypy/translator/js/database.py
pypy/dist/pypy/translator/js/exception.py
pypy/dist/pypy/translator/js/extfuncnode.py
pypy/dist/pypy/translator/js/funcnode.py
pypy/dist/pypy/translator/js/gc.py
pypy/dist/pypy/translator/js/js.py
pypy/dist/pypy/translator/js/opaquenode.py
pypy/dist/pypy/translator/js/opwriter.py
pypy/dist/pypy/translator/js/structnode.py
Log:
More things working, but no working tests yet.
The file looks javascript-ish. The cast are probably
incorrect and there are no globals/pbc's yet.
We are able to add two numbers though!
Modified: pypy/dist/pypy/translator/js/arraynode.py
==============================================================================
--- pypy/dist/pypy/translator/js/arraynode.py (original)
+++ pypy/dist/pypy/translator/js/arraynode.py Fri Oct 7 17:32:10 2005
@@ -1,8 +1,8 @@
import py
from pypy.rpython import lltype
-from pypy.translator.llvm.log import log
-from pypy.translator.llvm.node import LLVMNode, ConstantLLVMNode
-from pypy.translator.llvm import varsize
+from pypy.translator.js.node import LLVMNode, ConstantLLVMNode
+from pypy.translator.js import varsize
+from pypy.translator.js.log import log
log = log.structnode
class ArrayTypeNode(LLVMNode):
Modified: pypy/dist/pypy/translator/js/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/codewriter.py (original)
+++ pypy/dist/pypy/translator/js/codewriter.py Fri Oct 7 17:32:10 2005
@@ -1,144 +1,173 @@
import py
from itertools import count
-from pypy.translator.llvm.log import log
+from pypy.translator.js.log import log
log = log.codewriter
-DEFAULT_TAIL = '' #/tail
-DEFAULT_CCONV = 'fastcc' #ccc/fastcc
-
class CodeWriter(object):
- def __init__(self, f, genllvm):
+
+ tabstring = ' '
+
+ def __init__(self, f, js):
self.f = f
- self.genllvm = genllvm
- self.word = genllvm.db.get_machine_word()
- self.uword = genllvm.db.get_machine_uword()
-
- def append(self, line):
- self.f.write(line + '\n')
-
- def comment(self, line, indent=True):
- line = "// " + line
- if indent:
- self.indent(line)
+ self.js = js
+
+ def append(self, line, indentation_level=4):
+ if indentation_level:
+ s = self.tabstring * indentation_level
else:
- self.append(line)
+ s = ''
+ self.f.write(s + line + '\n')
+
+ def comment(self, line, indentation_level=4):
+ self.append("// " + line, indentation_level)
+
+ def llvm(self, line, indentation_level=4):
+ self.comment("LLVM " + line, indentation_level)
def newline(self):
self.append("")
- def indent(self, line):
- self.append(" " + line)
-
def label(self, name):
- self.newline()
- self.append("// QQQ %s:" % name)
+ self.append("case %d:" % name, 3)
+ openblock = label
+
+ def closeblock(self):
+ self.append('break')
def globalinstance(self, name, typeandata):
- self.append("// QQQ %s = %s global %s" % (name, "internal", typeandata))
+ self.llvm("%s = %s global %s" % (name, "internal", typeandata))
def structdef(self, name, typereprs):
- self.append("// QQQ %s = type { %s }" %(name, ", ".join(typereprs)))
+ self.llvm("%s = type { %s }" %(name, ", ".join(typereprs)))
def arraydef(self, name, lentype, typerepr):
- self.append("// QQQ %s = type { %s, [0 x %s] }" % (name, lentype, typerepr))
+ self.llvm("%s = type { %s, [0 x %s] }" % (name, lentype, typerepr))
def funcdef(self, name, rettyperepr, argtypereprs):
- self.append("// QQQ %s = type %s (%s)" % (name, rettyperepr,
+ self.llvm("%s = type %s (%s)" % (name, rettyperepr,
", ".join(argtypereprs)))
- def declare(self, decl, cconv=DEFAULT_CCONV):
- self.append("// QQQ declare %s %s" %(cconv, decl,))
+ def declare(self, decl):
+ #self.llvm("declare %s" % decl, 0)
+ pass
def startimpl(self):
- self.newline()
- self.append("// QQQ implementation")
- self.newline()
+ #self.llvm("implementation", 0)
+ pass
def br_uncond(self, blockname):
- self.indent("// QQQ br label %%%s" %(blockname,))
+ self.append('prevblock = block')
+ self.append('block = %d' % blockname)
+ #self.llvm("br label %s" %(blockname,))
def br(self, cond, blockname_false, blockname_true):
- self.indent("// QQQ br bool %s, label %%%s, label %%%s"
+ self.llvm("br bool %s, label %s, label %s"
% (cond, blockname_true, blockname_false))
def switch(self, intty, cond, defaultdest, value_label):
labels = ''
for value, label in value_label:
- labels += ' %s %s, label %%%s' % (intty, value, label)
- self.indent("// QQQ switch %s %s, label %%%s [%s ]"
+ labels += ' %s %s, label %s' % (intty, value, label)
+ self.llvm("switch %s %s, label %s [%s ]"
% (intty, cond, defaultdest, labels))
- def openfunc(self, decl, is_entrynode=False, cconv=DEFAULT_CCONV):
+ def openfunc(self, funcnode, blocks):
+ self.funcnode = funcnode
+ self.blocks = blocks
+ usedvars = {} #XXX could probably be limited to inputvars
+ for block in blocks:
+ for op in block.operations:
+ targetvar = self.js.db.repr_arg(op.result)
+ usedvars[targetvar] = True
self.newline()
- self.append("%s {" % decl)
+ self.append("function %s {" % self.funcnode.getdecl(), 0)
+ self.append("var %s" % ' = 0, '.join(usedvars.keys()), 1)
+ self.append("var block = 0", 1)
+ self.append("while (block != undefined) {", 1)
+ self.append("switch (block) {", 2)
def closefunc(self):
- self.append("}")
+ self.append("} // end of switch (block)", 2)
+ self.append("} // end of while (block != undefined)", 1)
+ self.append("} // end of function %s" % self.funcnode.getdecl(), 0)
def ret(self, type_, ref):
- if type_ == '// QQQ void':
- self.indent("// QQQ ret void")
+ if type_ == 'void':
+ self.append("return")
else:
- self.indent("// QQQ ret %s %s" % (type_, ref))
+ self.append("return " + ref)
def phi(self, targetvar, type_, refs, blocknames):
- assert targetvar.startswith('%')
assert refs and len(refs) == len(blocknames), "phi node requires blocks"
mergelist = ", ".join(
- ["[%s, %%%s]" % item
+ ["[%s, %s]" % item
for item in zip(refs, blocknames)])
s = "%s = phi %s %s" % (targetvar, type_, mergelist)
- self.indent('// QQQ ' + s)
+ self.llvm(s)
+ self.append('switch (prevblock) {')
+ for i, blockname in enumerate(blocknames):
+ self.append('case %d: %s = %s; break' % (blockname, targetvar, refs[i]), 5)
+ self.append('} // end of switch (prevblock)')
def binaryop(self, name, targetvar, type_, ref1, ref2):
- self.indent("// QQQ %s = %s %s %s, %s" % (targetvar, name, type_, ref1, ref2))
+ self.llvm("%s = %s %s %s, %s" % (targetvar, name, type_, ref1, ref2))
+ conv = { 'mul':'*', 'add':'+', 'sub':'-', 'div':'/' }
+ if name in conv:
+ c = conv[name]
+ self.append("%(targetvar)s = %(ref1)s %(c)s %(ref2)s" % locals())
+ else:
+ self.append("TODO: binaryop")
def shiftop(self, name, targetvar, type_, ref1, ref2):
- self.indent("// QQQ %s = %s %s %s, ubyte %s" % (targetvar, name, type_, ref1, ref2))
+ self.llvm("%s = %s %s %s, ubyte %s" % (targetvar, name, type_, ref1, ref2))
- def call(self, targetvar, returntype, functionref, argrefs, argtypes, label=None, except_label=None, tail=DEFAULT_TAIL, cconv=DEFAULT_CCONV):
- if cconv is not 'fastcc':
- tail_ = ''
- else:
- tail_ = tail
- if tail_:
- tail_ += ' '
+ def call(self, targetvar, returntype, functionref, argrefs, argtypes, label=None, except_label=None):
args = ", ".join(["%s %s" % item for item in zip(argtypes, argrefs)])
if except_label:
- self.genllvm.exceptionpolicy.invoke(self, targetvar, tail_, cconv, returntype, functionref, args, label, except_label)
+ self.js.exceptionpolicy.invoke(self, targetvar, returntype, functionref, args, label, except_label)
else:
if returntype == 'void':
- self.indent("// QQQ call void %s(%s)" % (functionref, args))
+ self.llvm("call void %s(%s)" % (functionref, args))
else:
- self.indent("// QQQ %s = call %s %s(%s)" % (targetvar, returntype, functionref, args))
+ self.llvm("%s = call %s %s(%s)" % (targetvar, returntype, functionref, args))
def cast(self, targetvar, fromtype, fromvar, targettype):
if fromtype == 'void' and targettype == 'void':
return
- self.indent("// QQQ %(targetvar)s = cast %(fromtype)s "
+ self.llvm("%(targetvar)s = cast %(fromtype)s "
"%(fromvar)s to %(targettype)s" % locals())
+ if targettype == fromtype:
+ self.append("%(targetvar)s = %(fromvar)s%(convfunc)s" % locals())
+ elif targettype in ('int','uint',):
+ self.append("%(targetvar)s = 0 + %(fromvar)s" % locals())
+ elif targettype in ('double',):
+ self.append("%(targetvar)s = 0.0 + %(fromvar)s" % locals())
+ elif targettype in ('bool',):
+ self.append("%(targetvar)s = %(fromvar)s == 0" % locals())
+ else:
+ self.append("// TODO %(targetvar)s = %(fromvar)s...()" % locals())
- def malloc(self, targetvar, type_, size=1, atomic=False, cconv=DEFAULT_CCONV):
- for s in self.genllvm.gcpolicy.malloc(targetvar, type_, size, atomic, self.word, self.uword).split('\n'):
- self.indent('// QQQ ' + s)
+ def malloc(self, targetvar, type_, size=1, atomic=False):
+ for s in self.js.gcpolicy.malloc(targetvar, type_, size, atomic, 'word', 'uword').split('\n'):
+ self.llvm(s)
def getelementptr(self, targetvar, type, typevar, *indices):
word = self.word
res = "%(targetvar)s = getelementptr %(type)s %(typevar)s, %(word)s 0, " % locals()
res += ", ".join(["%s %s" % (t, i) for t, i in indices])
- self.indent('// QQQ ' + res)
+ self.llvm(res)
def load(self, targetvar, targettype, ptr):
- self.indent("// QQQ %(targetvar)s = load %(targettype)s* %(ptr)s" % locals())
+ self.llvm("%(targetvar)s = load %(targettype)s* %(ptr)s" % locals())
def store(self, valuetype, valuevar, ptr):
- self.indent("// QQQ store %(valuetype)s %(valuevar)s, "
+ self.llvm("store %(valuetype)s %(valuevar)s, "
"%(valuetype)s* %(ptr)s" % locals())
def debugcomment(self, tempname, len, tmpname):
word = self.word
- res = "%s = call ccc %(word)s (sbyte*, ...)* %%printf(" % locals()
+ res = "%s = call ccc %(word)s (sbyte*, ...)* printf(" % locals()
res += "sbyte* getelementptr ([%s x sbyte]* %s, %(word)s 0, %(word)s 0) )" % locals()
res = res % (tmpname, len, tmpname)
- self.indent('// QQQ ' + res)
+ self.llvm(res)
Modified: pypy/dist/pypy/translator/js/database.py
==============================================================================
--- pypy/dist/pypy/translator/js/database.py (original)
+++ pypy/dist/pypy/translator/js/database.py Fri Oct 7 17:32:10 2005
@@ -1,17 +1,17 @@
import sys
-from pypy.translator.llvm.log import log
-from pypy.translator.llvm.funcnode import FuncNode, FuncTypeNode
-from pypy.translator.llvm.extfuncnode import ExternalFuncNode
-from pypy.translator.llvm.structnode import StructNode, StructVarsizeNode, \
+from pypy.translator.js.funcnode import FuncNode, FuncTypeNode
+from pypy.translator.js.extfuncnode import ExternalFuncNode
+from pypy.translator.js.structnode import StructNode, StructVarsizeNode, \
StructTypeNode, StructVarsizeTypeNode
-from pypy.translator.llvm.arraynode import ArrayNode, StrArrayNode, \
+from pypy.translator.js.arraynode import ArrayNode, StrArrayNode, \
VoidArrayNode, ArrayTypeNode, VoidArrayTypeNode
-from pypy.translator.llvm.opaquenode import OpaqueNode, OpaqueTypeNode
-from pypy.translator.llvm.node import ConstantLLVMNode
+from pypy.translator.js.opaquenode import OpaqueNode, OpaqueTypeNode
+from pypy.translator.js.node import ConstantLLVMNode
from pypy.rpython import lltype
from pypy.objspace.flow.model import Constant, Variable
+from pypy.translator.js.log import log
log = log.database
@@ -245,7 +245,7 @@
return node.get_ref()
else:
assert isinstance(arg, Variable)
- return "%" + str(arg)
+ return str(arg)
def repr_arg_type(self, arg):
assert isinstance(arg, (Constant, Variable))
@@ -300,7 +300,7 @@
def repr_tmpvar(self):
count = self._tmpcount
self._tmpcount += 1
- return "%tmp." + str(count)
+ return "tmp_" + str(count)
def repr_constructor(self, type_):
return self.obj2node[type_].constructor_ref
Modified: pypy/dist/pypy/translator/js/exception.py
==============================================================================
--- pypy/dist/pypy/translator/js/exception.py (original)
+++ pypy/dist/pypy/translator/js/exception.py Fri Oct 7 17:32:10 2005
@@ -1,6 +1,3 @@
-from pypy.translator.llvm.codewriter import DEFAULT_CCONV
-
-
class ExceptionPolicy:
RINGBUGGER_SIZE = 8192
RINGBUFFER_ENTRY_MAXSIZE = 16
@@ -51,13 +48,13 @@
def new(exceptionpolicy=None): #factory
exceptionpolicy = exceptionpolicy or 'explicit'
if exceptionpolicy == 'invokeunwind':
- from pypy.translator.llvm.exception import InvokeUnwindExceptionPolicy
+ from pypy.translator.js.exception import InvokeUnwindExceptionPolicy
exceptionpolicy = InvokeUnwindExceptionPolicy()
elif exceptionpolicy == 'explicit':
- from pypy.translator.llvm.exception import ExplicitExceptionPolicy
+ from pypy.translator.js.exception import ExplicitExceptionPolicy
exceptionpolicy = ExplicitExceptionPolicy()
elif exceptionpolicy == 'none':
- from pypy.translator.llvm.exception import NoneExceptionPolicy
+ from pypy.translator.js.exception import NoneExceptionPolicy
exceptionpolicy = NoneExceptionPolicy()
else:
raise Exception, 'unknown exceptionpolicy: ' + str(exceptionpolicy)
@@ -77,10 +74,9 @@
def llvmcode(self, entrynode):
returntype, entrypointname = entrynode.getdecl().split('%', 1)
noresult = self._noresult(returntype)
- 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
+ %%result = invoke %(returntype)s%%%(entrypointname)s to label %%no_exception except label %%exception
no_exception:
store %%RPYTHON_EXCEPTION_VTABLE* null, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
@@ -101,12 +97,12 @@
}
''' % locals() + self.RINGBUFFER_LLVMCODE
- def invoke(self, codewriter, targetvar, tail_, cconv, returntype, functionref, args, label, except_label):
+ def invoke(self, codewriter, targetvar, returntype, functionref, args, label, except_label):
labels = 'to label %%%s except label %%%s' % (label, except_label)
if returntype == 'void':
- codewriter.indent('%sinvoke %s void %s(%s) %s' % (tail_, cconv, functionref, args, labels))
+ codewriter.llvm('invoke void %s(%s) %s' % (functionref, args, labels))
else:
- codewriter.indent('%s = %sinvoke %s %s %s(%s) %s' % (targetvar, tail_, cconv, returntype, functionref, args, labels))
+ codewriter.llvm('%s = invoke %s %s(%s) %s' % (targetvar, returntype, functionref, args, labels))
def _is_raise_new_exception(self, db, graph, block):
from pypy.objspace.flow.model import mkentrymap
@@ -141,7 +137,7 @@
#Which is already stored in the global variables.
#So nothing needs to happen here!
- codewriter.indent('unwind')
+ codewriter.llvm('unwind')
def fetch_exceptions(self, codewriter, exc_found_labels, lltype_of_exception_type, lltype_of_exception_value):
for label, target, last_exc_type_var, last_exc_value_var in exc_found_labels:
@@ -154,7 +150,7 @@
def reraise(self, funcnode, codewriter):
codewriter.comment('reraise when exception is not caught')
- codewriter.indent('unwind')
+ codewriter.llvm('unwind')
def llc_options(self):
return '-enable-correct-eh-support'
@@ -167,11 +163,10 @@
def llvmcode(self, entrynode):
returntype, entrypointname = entrynode.getdecl().split('%', 1)
noresult = self._noresult(returntype)
- cconv = DEFAULT_CCONV
return '''
ccc %(returntype)s%%__entrypoint__%(entrypointname)s {
store %%RPYTHON_EXCEPTION_VTABLE* null, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
- %%result = call %(cconv)s %(returntype)s%%%(entrypointname)s
+ %%result = call %(returntype)s%%%(entrypointname)s
%%tmp = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
%%exc = seteq %%RPYTHON_EXCEPTION_VTABLE* %%tmp, null
br bool %%exc, label %%no_exception, label %%exception
@@ -203,18 +198,18 @@
create_exception_handling(translator, graph)
#translator.view()
- def invoke(self, codewriter, targetvar, tail_, cconv, returntype, functionref, args, label, except_label):
+ def invoke(self, codewriter, targetvar, returntype, functionref, args, label, except_label):
if returntype == 'void':
if functionref != '%keepalive': #XXX I think keepalive should not be the last operation here!
- codewriter.indent('%scall %s void %s(%s)' % (tail_, cconv, functionref, args))
+ codewriter.append('call void %s(%s)' % (functionref, args))
else:
- codewriter.indent('%s = %scall %s %s %s(%s)' % (targetvar, tail_, cconv, returntype, functionref, args))
+ codewriter.llvm('%s = call %s %s(%s)' % (targetvar, returntype, functionref, args))
tmp = '%%invoke.tmp.%d' % self.invoke_count
exc = '%%invoke.exc.%d' % self.invoke_count
self.invoke_count += 1
- codewriter.indent('%(tmp)s = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type' % locals())
- codewriter.indent('%(exc)s = seteq %%RPYTHON_EXCEPTION_VTABLE* %(tmp)s, null' % locals())
- codewriter.indent('br bool %(exc)s, label %%%(label)s, label %%%(except_label)s' % locals())
+ codewriter.llvm('%(tmp)s = load %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type' % locals())
+ codewriter.llvm('%(exc)s = seteq %%RPYTHON_EXCEPTION_VTABLE* %(tmp)s, null' % locals())
+ codewriter.llvm('br bool %(exc)s, label %%%(label)s, label %%%(except_label)s' % locals())
def write_exceptblock(self, funcnode, codewriter, block):
assert len(block.inputargs) == 2
@@ -228,7 +223,7 @@
codewriter.store(inputargtypes[0], inputargs[0], '%last_exception_type')
codewriter.store(inputargtypes[1], inputargs[1], '%last_exception_value')
- codewriter.indent('ret ' + noresult)
+ codewriter.llvm('ret ' + noresult)
def fetch_exceptions(self, codewriter, exc_found_labels, lltype_of_exception_type, lltype_of_exception_value):
for label, target, last_exc_type_var, last_exc_value_var in exc_found_labels:
@@ -243,7 +238,7 @@
def reraise(self, funcnode, codewriter):
noresult = self._nonoderesult(funcnode)
- codewriter.indent('ret ' + noresult)
+ codewriter.llvm('ret ' + noresult)
def llc_options(self):
return ''
Modified: pypy/dist/pypy/translator/js/extfuncnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/extfuncnode.py (original)
+++ pypy/dist/pypy/translator/js/extfuncnode.py Fri Oct 7 17:32:10 2005
@@ -1,6 +1,6 @@
import py
-from pypy.translator.llvm.node import ConstantLLVMNode
-from pypy.translator.llvm.log import log
+from pypy.translator.js.node import ConstantLLVMNode
+from pypy.translator.js.log import log
log = log.extfuncnode
class ExternalFuncNode(ConstantLLVMNode):
Modified: pypy/dist/pypy/translator/js/funcnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/funcnode.py (original)
+++ pypy/dist/pypy/translator/js/funcnode.py Fri Oct 7 17:32:10 2005
@@ -3,12 +3,12 @@
from pypy.objspace.flow.model import Block, Constant, Variable, Link
from pypy.objspace.flow.model import flatten, mkentrymap, traverse, last_exception
from pypy.rpython import lltype
-from pypy.translator.llvm.node import LLVMNode, ConstantLLVMNode
-from pypy.translator.llvm.opwriter import OpWriter
-from pypy.translator.llvm.log import log
-from pypy.translator.llvm.backendopt.removeexcmallocs import remove_exception_mallocs
-from pypy.translator.llvm.backendopt.mergemallocs import merge_mallocs
+from pypy.translator.js.node import LLVMNode, ConstantLLVMNode
+from pypy.translator.js.opwriter import OpWriter
+#from pypy.translator.js.backendopt.removeexcmallocs import remove_exception_mallocs
+#from pypy.translator.js.backendopt.mergemallocs import merge_mallocs
from pypy.translator.unsimplify import remove_double_links
+from pypy.translator.js.log import log
log = log.funcnode
class FuncTypeNode(LLVMNode):
@@ -33,16 +33,16 @@
codewriter.funcdef(self.ref, returntype, inputargtypes)
class FuncNode(ConstantLLVMNode):
- __slots__ = "db value ref graph block_to_name".split()
+ __slots__ = "db value ref graph blockindex".split()
def __init__(self, db, value):
self.db = db
self.value = value
- self.ref = self.make_ref('%pypy_', value.graph.name)
+ self.ref = self.make_ref('pypy_', value.graph.name)
self.graph = value.graph
self.db.genllvm.exceptionpolicy.transform(self.db.translator, self.graph)
- remove_exception_mallocs(self.db.translator, self.graph, self.ref)
+ #remove_exception_mallocs(self.db.translator, self.graph, self.ref)
#merge_mallocs(self.db.translator, self.graph, self.ref)
remove_double_links(self.db.translator, self.graph)
@@ -78,21 +78,22 @@
def writeimpl(self, codewriter):
graph = self.graph
log.writeimpl(graph.name)
- codewriter.openfunc(self.getdecl(), self is self.db.entrynode)
nextblock = graph.startblock
args = graph.startblock.inputargs
- l = [x for x in flatten(graph) if isinstance(x, Block)]
- self.block_to_name = {}
- for i, block in enumerate(l):
- self.block_to_name[block] = "block%s" % i
- for block in l:
- codewriter.label(self.block_to_name[block])
+ blocks = [x for x in flatten(graph) if isinstance(x, Block)]
+ self.blockindex= {}
+ for i, block in enumerate(blocks):
+ self.blockindex[block] = i
+ codewriter.openfunc(self, blocks)
+ for block in blocks:
+ codewriter.openblock(self.blockindex[block])
for name in 'startblock returnblock exceptblock'.split():
if block is getattr(graph, name):
getattr(self, 'write_' + name)(codewriter, block)
break
else:
self.write_block(codewriter, block)
+ codewriter.closeblock()
codewriter.closefunc()
def writecomments(self, codewriter):
@@ -134,10 +135,10 @@
inputargs = self.db.repr_arg_multi(startblock_inputargs)
inputargtypes = self.db.repr_arg_type_multi(startblock_inputargs)
returntype = self.db.repr_arg_type(self.graph.returnblock.inputargs[0])
- result = "%s %s" % (returntype, self.ref)
- args = ["%s %s" % item for item in zip(inputargtypes, inputargs)]
- result += "(%s)" % ", ".join(args)
- return result
+ #result = "%s %s" % (returntype, self.ref)
+ #args = ["%s %s" % item for item in zip(inputargtypes, inputargs)]
+ #result += "(%s)" % ", ".join(args)
+ return self.ref + "(%s)" % ", ".join(inputargs)
def write_block(self, codewriter, block):
self.write_block_phi_nodes(codewriter, block)
@@ -152,12 +153,11 @@
inputargtypes = self.db.repr_arg_type_multi(block.inputargs)
for i, (arg, type_) in enumerate(zip(inputargs, inputargtypes)):
names = self.db.repr_arg_multi([link.args[i] for link in entrylinks])
- blocknames = [self.block_to_name[link.prevblock]
- for link in entrylinks]
+ blocknames = [self.blockindex[link.prevblock] for link in entrylinks]
for i, link in enumerate(entrylinks): #XXX refactor into a transformation
if link.prevblock.exitswitch == Constant(last_exception) and \
link.prevblock.exits[0].target != block:
- blocknames[i] += '_exception_found_branchto_' + self.block_to_name[block]
+ blocknames[i] += '_exception_found_branchto_' + self.blockindex[block]
data.append( (arg, type_, names, blocknames) )
return data
@@ -172,11 +172,11 @@
#codewriter.comment('FuncNode(ConstantLLVMNode) *last_exception* write_block_branches @%s@' % str(block.exits))
return
if len(block.exits) == 1:
- codewriter.br_uncond(self.block_to_name[block.exits[0].target])
+ codewriter.br_uncond(self.blockindex[block.exits[0].target])
elif len(block.exits) == 2:
cond = self.db.repr_arg(block.exitswitch)
- codewriter.br(cond, self.block_to_name[block.exits[0].target],
- self.block_to_name[block.exits[1].target])
+ codewriter.br(cond, self.blockindex[block.exits[0].target],
+ self.blockindex[block.exits[1].target])
def write_block_operations(self, codewriter, block):
opwriter = OpWriter(self.db, codewriter, self, block)
Modified: pypy/dist/pypy/translator/js/gc.py
==============================================================================
--- pypy/dist/pypy/translator/js/gc.py (original)
+++ pypy/dist/pypy/translator/js/gc.py Fri Oct 7 17:32:10 2005
@@ -28,13 +28,13 @@
gcpolicy = 'none'
if gcpolicy == 'boehm':
- from pypy.translator.llvm.gc import BoehmGcPolicy
+ from pypy.translator.js.gc import BoehmGcPolicy
gcpolicy = BoehmGcPolicy()
elif gcpolicy == 'ref':
- from pypy.translator.llvm.gc import RefcountingGcPolicy
+ from pypy.translator.js.gc import RefcountingGcPolicy
gcpolicy = RefcountingGcPolicy()
elif gcpolicy == 'none':
- from pypy.translator.llvm.gc import NoneGcPolicy
+ from pypy.translator.js.gc import NoneGcPolicy
gcpolicy = NoneGcPolicy()
else:
raise Exception, 'unknown gcpolicy: ' + str(gcpolicy)
Modified: pypy/dist/pypy/translator/js/js.py
==============================================================================
--- pypy/dist/pypy/translator/js/js.py (original)
+++ pypy/dist/pypy/translator/js/js.py Fri Oct 7 17:32:10 2005
@@ -3,7 +3,7 @@
http://webreference.com/javascript/reference/core_ref/
http://webreference.com/programming/javascript/
http://mochikit.com/
-
+ http://www.mozilla.org/js/spidermonkey/
'''
#import os
@@ -13,10 +13,10 @@
import py
-from pypy.translator.llvm.database import Database
from pypy.rpython.rmodel import inputconst, getfunctionptr
from pypy.rpython import lltype
from pypy.tool.udir import udir
+from pypy.translator.js.database import Database
from pypy.translator.js.codewriter import CodeWriter
from pypy.translator.js.gc import GcPolicy
from pypy.translator.js.exception import ExceptionPolicy
@@ -51,8 +51,8 @@
# set up all nodes
self.db.setup_all()
- self.entrynode = self.db.set_entrynode(entry_point)
- entryfunc_name = self.entrynode.getdecl().split('%', 1)[1].split('(')[0]
+ #self.entrynode = self.db.set_entrynode(entry_point)
+ #entryfunc_name = self.entrynode.getdecl().split('%', 1)[1].split('(')[0]
## post set up externs
#extern_decls = post_setup_externs(self.db)
@@ -79,14 +79,12 @@
self.filename = udir.join(func.func_name + postfix).new(ext='.js')
f = open(str(self.filename),'w')
codewriter = CodeWriter(f, self)
- comment = codewriter.comment
- nl = codewriter.newline
#if using_external_functions:
- # nl(); comment("External Function Declarations") ; nl()
+ # codewriter.comment("External Function Declarations")
# codewriter.append(llexterns_header)
- nl(); comment("Type Declarations"); nl()
+ codewriter.comment("Type Declarations", 0)
#for c_name, obj in extern_decls:
# if isinstance(obj, lltype.LowLevelType):
# if isinstance(obj, lltype.Ptr):
@@ -97,18 +95,18 @@
for typ_decl in self.db.getnodes():
typ_decl.writedatatypedecl(codewriter)
- nl(); comment("Global Data") ; nl()
+ codewriter.comment("Global Data", 0)
for typ_decl in self.db.getnodes():
typ_decl.writeglobalconstants(codewriter)
- nl(); comment("Function Prototypes") ; nl()
+ codewriter.comment("Function Prototypes", 0)
#codewriter.append(extdeclarations)
#codewriter.append(self.gcpolicy.declarations())
for typ_decl in self.db.getnodes():
typ_decl.writedecl(codewriter)
- nl(); comment("Function Implementation")
+ codewriter.comment("Function Implementation", 0)
codewriter.startimpl()
for typ_decl in self.db.getnodes():
@@ -137,16 +135,18 @@
# depdone[dep] = True
#
#if using_external_functions:
- # nl(); comment("External Function Implementation") ; nl()
+ # codewriter.comment("External Function Implementation", 0)
# codewriter.append(llexterns_functions)
- comment("Wrapper code for the Javascript CLI") ; nl()
- graph = self.db.entrynode.graph
+ codewriter.newline()
+ codewriter.comment("Wrapper code for the Javascript CLI", 0)
+ codewriter.newline()
+ graph = self.db.obj2node[entry_point].graph
startblock = graph.startblock
args = ','.join(['arguments[%d]' % i for i,v in enumerate(startblock.inputargs)])
- wrappercode = 'pypy_%s(%s);\n' % (graph.name, args)
- codewriter.indent(wrappercode)
-
- comment("End of file") ; nl()
+ wrappercode = 'print(pypy_%s(%s))' % (graph.name, args)
+ codewriter.append(wrappercode, 0)
+ codewriter.newline()
+ codewriter.comment("EOF", 0)
log('Written:', self.filename)
return self.filename
Modified: pypy/dist/pypy/translator/js/opaquenode.py
==============================================================================
--- pypy/dist/pypy/translator/js/opaquenode.py (original)
+++ pypy/dist/pypy/translator/js/opaquenode.py Fri Oct 7 17:32:10 2005
@@ -1,4 +1,4 @@
-from pypy.translator.llvm.node import LLVMNode, ConstantLLVMNode
+from pypy.translator.js.node import LLVMNode, ConstantLLVMNode
from pypy.rpython import lltype
class OpaqueTypeNode(LLVMNode):
Modified: pypy/dist/pypy/translator/js/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/js/opwriter.py (original)
+++ pypy/dist/pypy/translator/js/opwriter.py Fri Oct 7 17:32:10 2005
@@ -1,9 +1,9 @@
import py
from pypy.objspace.flow.model import Constant
from pypy.rpython import lltype
-from pypy.translator.llvm.module.extfunction import extfunctions
-from pypy.translator.llvm.extfuncnode import ExternalFuncNode
-from pypy.translator.llvm.log import log
+#from pypy.translator.js.module.extfunction import extfunctions
+from pypy.translator.js.extfuncnode import ExternalFuncNode
+from pypy.translator.js.log import log
log = log.opwriter
class OpWriter(object):
@@ -286,8 +286,8 @@
def last_exception_type_ptr(self, op):
e = self.db.translator.rtyper.getexceptiondata()
- lltype_of_exception_type = ('%structtype.' + e.lltype_of_exception_type.TO.__name__ + '*')
- self.codewriter.load('%'+str(op.result), lltype_of_exception_type, '%last_exception_type')
+ lltype_of_exception_type = ('structtype.' + e.lltype_of_exception_type.TO.__name__ + '*')
+ self.codewriter.load('%'+str(op.result), lltype_of_exception_type, 'last_exception_type')
def invoke(self, op):
op_args = [arg for arg in op.args
@@ -319,8 +319,8 @@
argrefs = self.db.repr_arg_multi(op_args[1:])
argtypes = self.db.repr_arg_type_multi(op_args[1:])
- none_label = self.node.block_to_name[link.target]
- block_label = self.node.block_to_name[self.block]
+ none_label = self.node.blockindex[link.target]
+ block_label = self.node.blockindex[self.block]
exc_label = block_label + '_exception_handling'
if self.db.is_function_ptr(op.result): #use longhand form
@@ -329,11 +329,11 @@
argtypes, none_label, exc_label)
e = self.db.translator.rtyper.getexceptiondata()
- ll_exception_match = '%pypy_' + e.ll_exception_match.__name__
- lltype_of_exception_type = ('%structtype.' +
+ ll_exception_match = 'pypy_' + e.ll_exception_match.__name__
+ lltype_of_exception_type = ('structtype.' +
e.lltype_of_exception_type.TO.__name__
+ '*')
- lltype_of_exception_value = ('%structtype.' +
+ lltype_of_exception_value = ('structtype.' +
e.lltype_of_exception_value.TO.__name__
+ '*')
@@ -346,7 +346,7 @@
etype = self.db.obj2node[link.llexitcase._obj]
current_exception_type = etype.get_ref()
- target = self.node.block_to_name[link.target]
+ target = self.node.blockindex[link.target]
exc_found_label = block_label + '_exception_found_branchto_' + target
last_exc_type_var, last_exc_value_var = None, None
@@ -355,9 +355,9 @@
for name, blockname in zip(names, blocknames):
if blockname != exc_found_label:
continue
- if name.startswith('%last_exception_'):
+ if name.startswith('last_exception_'):
last_exc_type_var = name
- if name.startswith('%last_exc_value_'):
+ if name.startswith('last_exc_value_'):
last_exc_value_var = name
t = (exc_found_label,target,last_exc_type_var,last_exc_value_var)
@@ -371,7 +371,7 @@
else: #catch specific exception (class) type
if not last_exception_type: #load pointer only once
last_exception_type = self.db.repr_tmpvar()
- self.codewriter.load(last_exception_type, lltype_of_exception_type, '%last_exception_type')
+ self.codewriter.load(last_exception_type, lltype_of_exception_type, 'last_exception_type')
self.codewriter.newline()
ll_issubclass_cond = self.db.repr_tmpvar()
self.codewriter.call(ll_issubclass_cond,
@@ -394,9 +394,9 @@
tmpvar1 = self.db.repr_tmpvar()
tmpvar2 = self.db.repr_tmpvar()
tmpvar3 = self.db.repr_tmpvar()
- self.codewriter.indent('%(tmpvar1)s = getelementptr %(type_)s* null, int 1' % locals())
+ self.codewriter.append('%(tmpvar1)s = getelementptr %(type_)s* null, int 1' % locals())
self.codewriter.cast(tmpvar2, type_+'*', tmpvar1, 'uint')
- self.codewriter.call(tmpvar3, 'sbyte*', '%malloc_exception', [tmpvar2], ['uint'])
+ self.codewriter.call(tmpvar3, 'sbyte*', 'malloc_exception', [tmpvar2], ['uint'])
self.codewriter.cast(targetvar, 'sbyte*', tmpvar3, type_+'*')
def malloc(self, op):
Modified: pypy/dist/pypy/translator/js/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/js/structnode.py (original)
+++ pypy/dist/pypy/translator/js/structnode.py Fri Oct 7 17:32:10 2005
@@ -1,8 +1,8 @@
import py
-from pypy.translator.llvm.log import log
-from pypy.translator.llvm.node import LLVMNode, ConstantLLVMNode
-from pypy.translator.llvm import varsize
+from pypy.translator.js.node import LLVMNode, ConstantLLVMNode
+from pypy.translator.js import varsize
from pypy.rpython import lltype
+from pypy.translator.js.log import log
log = log.structnode
More information about the Pypy-commit
mailing list