[pypy-svn] r18484 - in pypy/dist/pypy/translator/asm: . ppc
mwh at codespeak.net
mwh at codespeak.net
Wed Oct 12 17:00:48 CEST 2005
Author: mwh
Date: Wed Oct 12 17:00:46 2005
New Revision: 18484
Added:
pypy/dist/pypy/translator/asm/ppc/
pypy/dist/pypy/translator/asm/ppc/__init__.py
pypy/dist/pypy/translator/asm/ppc/codegen.py
Modified:
pypy/dist/pypy/translator/asm/genasm.py
pypy/dist/pypy/translator/asm/infregmachine.py
Log:
move some data around
Modified: pypy/dist/pypy/translator/asm/genasm.py
==============================================================================
--- pypy/dist/pypy/translator/asm/genasm.py (original)
+++ pypy/dist/pypy/translator/asm/genasm.py Wed Oct 12 17:00:46 2005
@@ -59,16 +59,8 @@
return r
elif processor == 'ppc':
- maxregs = 0
- for insn in g.assembler.instructions:
- if isinstance(insn, str):
- continue
- for r in insn.registers_used():
- maxregs = max(r, maxregs)
- fin = g.assembler.allocate_registers(30)
- return make_func(fin.assemble(), 'i',
- 'i'*len(graph.startblock.inputargs),
- maxregs)
+ from pypy.translator.asm.ppc import codegen
+ return codegen.make_native_code(graph, g.assembler.instructions)
class FuncGenerator(object):
Modified: pypy/dist/pypy/translator/asm/infregmachine.py
==============================================================================
--- pypy/dist/pypy/translator/asm/infregmachine.py (original)
+++ pypy/dist/pypy/translator/asm/infregmachine.py Wed Oct 12 17:00:46 2005
@@ -61,78 +61,3 @@
if isinstance(i, str):
i += ':'
print i
-
- def allocate_registers(self, nregisters):
- from pypy.translator.asm import regalloc
- r = FiniteRegisterAssembler(nregisters)
- r.instructions = regalloc.regalloc(self.instructions, nregisters)
- r.dump()
- return r
-
-class FiniteRegisterAssembler(Assembler):
- def __init__(self, nregisters):
- Assembler.__init__(self)
- self.nregisters = nregisters
-
- def assemble(self):
- from pypy.translator.asm.ppcgen import ppc_assembler
- A = ppc_assembler.PPCAssembler()
-
- for i in self.instructions:
- if isinstance(i, str):
- A.label(i)
- continue
-
- getattr(self, i.name)(A, *i.arguments)
-
- return A
-
- def LIA(self, A, dest, argindex):
- assert dest + 2 == argindex.value + 3
-
- def LOAD(self, A, dest, value):
- value = value.value
- assert isinstance(value, int)
- assert -30000 < value < 30000
- A.li(dest + 2, value)
-
- def int_add(self, A, dest, a, b):
- A.add(dest + 2, a + 2, b + 2)
-
- def int_sub(self, A, dest, a, b):
- A.sub(dest + 2, a + 2, b + 2)
-
- def int_mul(self, A, dest, a, b):
- A.mullw(dest + 2, a + 2, b + 2)
-
- def int_gt(self, A, a, b):
- A.cmpw(a + 2, b + 2)
- A.crmove(0, 1)
-
- def int_lt(self, A, a, b):
- A.cmpw(a + 2, b + 2)
-
- def JT(self, A, branch):
- # should be "A.bt(BI=0, BD=branch)" but this crashes.
- A.blt(branch)
-
- def J(self, A, branch):
- A.b(branch)
-
- def RETPYTHON(self, A, reg):
- A.mr(3, reg + 2)
- A.blr()
-
- def MOV(self, A, dest, src):
- A.mr(dest + 2, src + 2)
-
- def EXCH(self, A, a, b):
- A.xor(a+2, a+2, b+2)
- A.xor(b+2, b+2, a+2)
- A.xor(a+2, a+2, b+2)
-
- def STORESTACK(self, A, s, v):
- A.stw(v+2, 1, 24+4*s.value)
-
- def LOADSTACK(self, A, v, s):
- A.lwz(v+2, 1, 24+4*s.value)
Added: pypy/dist/pypy/translator/asm/ppc/__init__.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/asm/ppc/__init__.py Wed Oct 12 17:00:46 2005
@@ -0,0 +1 @@
+# nowt
Added: pypy/dist/pypy/translator/asm/ppc/codegen.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/asm/ppc/codegen.py Wed Oct 12 17:00:46 2005
@@ -0,0 +1,86 @@
+
+def make_native_code(graph, infreginsns):
+ from pypy.translator.asm.ppcgen.func_builder import make_func
+ maxregs = 0
+ for insn in infreginsns:
+ if isinstance(insn, str):
+ continue
+ for r in insn.registers_used():
+ maxregs = max(r, maxregs)
+
+ from pypy.translator.asm import regalloc
+
+ insns = regalloc.regalloc(infreginsns, 30)
+
+ codegen = PPCCodeGen()
+
+ return make_func(codegen.assemble(insns), 'i',
+ 'i'*len(graph.startblock.inputargs),
+ maxregs)
+
+
+class PPCCodeGen(object):
+
+ def assemble(self, insns):
+ from pypy.translator.asm.ppcgen import ppc_assembler
+ A = ppc_assembler.PPCAssembler()
+
+ for i in insns:
+ if isinstance(i, str):
+ A.label(i)
+ continue
+
+ getattr(self, i.name)(A, *i.arguments)
+
+ return A
+
+ def LIA(self, A, dest, argindex):
+ assert dest + 2 == argindex.value + 3
+
+ def LOAD(self, A, dest, value):
+ value = value.value
+ assert isinstance(value, int)
+ assert -30000 < value < 30000
+ A.li(dest + 2, value)
+
+ def int_add(self, A, dest, a, b):
+ A.add(dest + 2, a + 2, b + 2)
+
+ def int_sub(self, A, dest, a, b):
+ A.sub(dest + 2, a + 2, b + 2)
+
+ def int_mul(self, A, dest, a, b):
+ A.mullw(dest + 2, a + 2, b + 2)
+
+ def int_gt(self, A, a, b):
+ A.cmpw(a + 2, b + 2)
+ A.crmove(0, 1)
+
+ def int_lt(self, A, a, b):
+ A.cmpw(a + 2, b + 2)
+
+ def JT(self, A, branch):
+ # should be "A.bt(BI=0, BD=branch)" but this crashes.
+ A.blt(branch)
+
+ def J(self, A, branch):
+ A.b(branch)
+
+ def RETPYTHON(self, A, reg):
+ A.mr(3, reg + 2)
+ A.blr()
+
+ def MOV(self, A, dest, src):
+ A.mr(dest + 2, src + 2)
+
+ def EXCH(self, A, a, b):
+ A.xor(a+2, a+2, b+2)
+ A.xor(b+2, b+2, a+2)
+ A.xor(a+2, a+2, b+2)
+
+ def STORESTACK(self, A, s, v):
+ A.stw(v+2, 1, 24+4*s.value)
+
+ def LOADSTACK(self, A, v, s):
+ A.lwz(v+2, 1, 24+4*s.value)
+
More information about the Pypy-commit
mailing list