[pypy-svn] r50676 - pypy/dist/pypy/jit/codegen/demo
arigo at codespeak.net
arigo at codespeak.net
Wed Jan 16 16:59:33 CET 2008
Author: arigo
Date: Wed Jan 16 16:59:33 2008
New Revision: 50676
Added:
pypy/dist/pypy/jit/codegen/demo/asm386.py (contents, props changed)
Log:
Convert a tool I had for a long time in my working copy to a demo.
Added: pypy/dist/pypy/jit/codegen/demo/asm386.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/demo/asm386.py Wed Jan 16 16:59:33 2008
@@ -0,0 +1,57 @@
+#! /usr/bin/env python
+"""
+A demo using the ri386 module to assemble instructions.
+"""
+
+from pypy.jit.codegen.i386.ri386 import *
+
+class CodeBuilder(I386CodeBuilder):
+ def __init__(self):
+ self.buffer = []
+
+ def write(self, data):
+ for c in data:
+ self.buffer.append(c) # extend the list of characters
+
+ def tell(self):
+ return len(self.buffer)
+
+ def getvalue(self):
+ return ''.join(self.buffer)
+
+ def as_string(self):
+ lst = []
+ for c in self.buffer:
+ lst.append('%02x' % ord(c))
+ return ' '.join(lst)
+
+ def dump(self):
+ print self.as_string()
+ del self.buffer[:]
+
+
+def do(insn, *args):
+ s = CodeBuilder()
+ getattr(s, insn)(*args)
+ print '%24s ' % (s.as_string(),),
+ print insn,
+ for a in args:
+ print a,
+ print
+
+
+do('PUSH', ebp)
+do('MOV', ebp, esp)
+do('MOV', ecx, mem(ebp, 12))
+
+do('LEA', eax, memSIB(None, ecx, 2, 4))
+
+do('SUB', esp, eax)
+do('ADD', esp, eax)
+
+do('LEA', ecx, memSIB(edx, ecx, 2, 0))
+
+do('CALL', mem(ebp, 8))
+
+do('MOV', esp, ebp)
+
More information about the Pypy-commit
mailing list