[pypy-svn] r36776 - pypy/dist/pypy/jit/codegen/llvm
ericvrp at codespeak.net
ericvrp at codespeak.net
Mon Jan 15 13:30:03 CET 2007
Author: ericvrp
Date: Mon Jan 15 13:30:00 2007
New Revision: 36776
Added:
pypy/dist/pypy/jit/codegen/llvm/cast.py (contents, props changed)
pypy/dist/pypy/jit/codegen/llvm/genvarorconst.py (contents, props changed)
pypy/dist/pypy/jit/codegen/llvm/logger.py (contents, props changed)
Modified:
pypy/dist/pypy/jit/codegen/llvm/rgenop.py
Log:
some refactoring
Added: pypy/dist/pypy/jit/codegen/llvm/cast.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/llvm/cast.py Mon Jan 15 13:30:00 2007
@@ -0,0 +1,8 @@
+import py
+from pypy.jit.codegen.llvm.genvarorconst import Var, BoolConst, CharConst,\
+ IntConst, UIntConst, FloatConst, AddrConst
+from pypy.jit.codegen.llvm.compatibility import icmp, scmp, ucmp, fcmp, inttoptr,\
+ trunc, zext, bitcast, inttoptr, shr_prefix, define, i1, i8, i16, i32, f64
+
+def cast(osrc, dst):
+ print src, '->', dst
Added: pypy/dist/pypy/jit/codegen/llvm/genvarorconst.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/llvm/genvarorconst.py Mon Jan 15 13:30:00 2007
@@ -0,0 +1,174 @@
+import py, os
+from pypy.rlib.objectmodel import specialize
+from pypy.rpython.lltypesystem import lltype, llmemory
+from pypy.rlib.rarithmetic import intmask
+from pypy.jit.codegen.model import GenVar, GenConst
+from pypy.jit.codegen.llvm.compatibility import i1, i8, i16, i32, f64
+
+
+pi8 = i8 + '*'
+pi32 = i32 + '*'
+u32 = i32
+
+
+class Count(object):
+ n_vars = 0
+ n_labels = 0
+
+ def newlabel(self):
+ label = 'L%d' % (self.n_labels,)
+ self.n_labels += 1
+ return label
+
+count = Count()
+
+
+class Var(GenVar):
+
+ def __init__(self, type):
+ self.n = count.n_vars
+ self.type = type
+ self.signed = type is i32 or type is f64
+ count.n_vars += 1
+
+ def operand(self):
+ return '%s %s' % (self.type, self.operand2())
+
+ def operand2(self):
+ return '%%v%d' % (self.n,)
+
+
+class GenericConst(GenConst):
+
+ def operand(self):
+ return '%s %s' % (self.type, self.operand2())
+
+ @specialize.arg(1)
+ def revealconst(self, T):
+ if isinstance(T, lltype.Ptr):
+ return lltype.cast_int_to_ptr(T, self.get_integer_value())
+ elif T is llmemory.Address:
+ return llmemory.cast_int_to_adr(self.get_integer_value())
+ else:
+ return lltype.cast_primitive(T, self.get_integer_value())
+
+
+class BoolConst(GenericConst):
+ type = i1
+ signed = False
+
+ def __init__(self, value):
+ self.value = bool(value)
+
+ def operand2(self):
+ if self.value:
+ return 'true'
+ else:
+ return 'false'
+
+ def get_integer_value(self):
+ return int(self.value)
+
+
+class CharConst(GenericConst):
+ type = i8
+ signed = False
+
+ def __init__(self, value):
+ self.value = ord(value)
+
+ def operand2(self):
+ return '%d' % self.value
+
+ def get_integer_value(self):
+ return self.value
+
+
+class UniCharConst(GenericConst):
+ type = i32
+ signed = True
+
+ def __init__(self, value):
+ self.value = unicode(value)
+
+ def operand2(self):
+ return '%s' % self.value
+
+ def get_integer_value(self):
+ return int(self.value)
+
+
+class IntConst(GenericConst):
+ type = i32
+ signed = True
+
+ def __init__(self, value):
+ self.value = int(value)
+
+ def operand2(self):
+ return str(self.value)
+
+ def get_integer_value(self):
+ return self.value
+
+
+class UIntConst(GenericConst):
+ type = u32
+ signed = False
+
+ def __init__(self, value):
+ self.value = value
+
+ def operand2(self):
+ return str(self.value)
+
+ def get_integer_value(self):
+ return intmask(self.value)
+
+
+class FloatConst(GenericConst):
+ type = f64
+ signed = True
+
+ def __init__(self, value):
+ self.value = float(value)
+
+ def operand2(self):
+ return str(self.value)
+
+ @specialize.arg(1)
+ def revealconst(self, T):
+ assert T is lltype.Float
+ return self.value
+
+
+class AddrConst(GenConst):
+ type = pi8
+ signed = False
+ addr = llmemory.NULL #have 'addr' even when not instantiated
+
+ def __init__(self, addr):
+ self.addr = addr
+
+ def operand(self):
+ return '%s %s' % (self.type, self.operand2())
+
+ def operand2(self):
+ addr = self.addr
+ s = str(llmemory.cast_adr_to_int(addr))
+ if s == '0':
+ s = 'null'
+ return s
+
+ @specialize.arg(1)
+ def revealconst(self, T):
+ if T is llmemory.Address:
+ return self.addr
+ elif isinstance(T, lltype.Ptr):
+ return llmemory.cast_adr_to_ptr(self.addr, T)
+ elif T is lltype.Signed:
+ return llmemory.cast_adr_to_int(self.addr)
+ else:
+ msg = 'XXX not implemented'
+ logger.dump(msg)
+ assert 0, msg
Added: pypy/dist/pypy/jit/codegen/llvm/logger.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/jit/codegen/llvm/logger.py Mon Jan 15 13:30:00 2007
@@ -0,0 +1,56 @@
+import py, os
+from pypy.rlib.objectmodel import we_are_translated
+from pypy.jit.codegen.llvm.conftest import option
+
+
+PRINT_DEBUG = option.print_debug
+
+
+class Logger:
+
+ enabled = True
+ log_fd = -1
+
+ def _freeze_(self):
+ # reset the machine_code_dumper global instance to its default state
+ if self.log_fd >= 0:
+ os.close(self.log_fd)
+ self.__dict__.clear()
+ return False
+
+ def open(self):
+ if not self.enabled:
+ return False
+ if self.log_fd < 0:
+ # check the environment for a file name
+ from pypy.rlib.ros import getenv
+ s = getenv('PYPYJITLOG')
+ if not s:
+ self.enabled = False
+ return False
+ try:
+ flags = os.O_WRONLY|os.O_CREAT|os.O_TRUNC
+ self.log_fd = os.open(s, flags, 0666)
+ except OSError:
+ os.write(2, "could not create log file\n")
+ self.enabled = False
+ return False
+ # log the executable name
+ from pypy.jit.codegen.hlinfo import highleveljitinfo
+ if highleveljitinfo.sys_executable:
+ os.write(self.log_fd, 'SYS_EXECUTABLE %s\n' % (
+ highleveljitinfo.sys_executable,))
+ return True
+
+ def dump(self, s):
+ if not self.open():
+ return
+ os.write(self.log_fd, str(s) + '\n')
+
+logger = Logger()
+
+
+def log(s):
+ if PRINT_DEBUG and not we_are_translated():
+ print str(s)
+ logger.dump(s)
Modified: pypy/dist/pypy/jit/codegen/llvm/rgenop.py
==============================================================================
--- pypy/dist/pypy/jit/codegen/llvm/rgenop.py (original)
+++ pypy/dist/pypy/jit/codegen/llvm/rgenop.py Mon Jan 15 13:30:00 2007
@@ -8,6 +8,10 @@
from pypy.rlib.objectmodel import we_are_translated
from pypy.jit.codegen.i386.rgenop import gc_malloc_fnaddr
from pypy.jit.codegen.llvm.conftest import option
+from pypy.jit.codegen.llvm.genvarorconst import count, Var, BoolConst, CharConst,\
+ IntConst, UIntConst, FloatConst, AddrConst
+from pypy.jit.codegen.llvm.logger import logger, log
+from pypy.jit.codegen.llvm.cast import cast
from pypy.jit.codegen.llvm.compatibility import icmp, scmp, ucmp, fcmp, inttoptr,\
trunc, zext, bitcast, inttoptr, shr_prefix, define, i1, i8, i16, i32, f64
@@ -25,219 +29,6 @@
pass
-class Logger:
-
- enabled = True
- log_fd = -1
-
- def _freeze_(self):
- # reset the machine_code_dumper global instance to its default state
- if self.log_fd >= 0:
- os.close(self.log_fd)
- self.__dict__.clear()
- return False
-
- def open(self):
- if not self.enabled:
- return False
- if self.log_fd < 0:
- # check the environment for a file name
- from pypy.rlib.ros import getenv
- s = getenv('PYPYJITLOG')
- if not s:
- self.enabled = False
- return False
- try:
- flags = os.O_WRONLY|os.O_CREAT|os.O_TRUNC
- self.log_fd = os.open(s, flags, 0666)
- except OSError:
- os.write(2, "could not create log file\n")
- self.enabled = False
- return False
- # log the executable name
- from pypy.jit.codegen.hlinfo import highleveljitinfo
- if highleveljitinfo.sys_executable:
- os.write(self.log_fd, 'SYS_EXECUTABLE %s\n' % (
- highleveljitinfo.sys_executable,))
- return True
-
- def dump(self, s):
- if not self.open():
- return
- os.write(self.log_fd, str(s) + '\n')
-
-logger = Logger()
-
-
-def log(s):
- if PRINT_DEBUG and not we_are_translated():
- print str(s)
- logger.dump(s)
-
-
-class Count(object):
- n_vars = 0
- n_labels = 0
-
- def newlabel(self):
- label = 'L%d' % (self.n_labels,)
- self.n_labels += 1
- return label
-
-count = Count()
-
-
-class Var(GenVar):
-
- def __init__(self, type):
- self.n = count.n_vars
- self.type = type
- self.signed = type is i32 or type is f64
- count.n_vars += 1
-
- def operand(self):
- return '%s %s' % (self.type, self.operand2())
-
- def operand2(self):
- return '%%v%d' % (self.n,)
-
-
-class GenericConst(GenConst):
-
- def operand(self):
- return '%s %s' % (self.type, self.operand2())
-
- @specialize.arg(1)
- def revealconst(self, T):
- if isinstance(T, lltype.Ptr):
- return lltype.cast_int_to_ptr(T, self.get_integer_value())
- elif T is llmemory.Address:
- return llmemory.cast_int_to_adr(self.get_integer_value())
- else:
- return lltype.cast_primitive(T, self.get_integer_value())
-
-
-class BoolConst(GenericConst):
- type = i1
- signed = False
-
- def __init__(self, value):
- self.value = bool(value)
-
- def operand2(self):
- if self.value:
- return 'true'
- else:
- return 'false'
-
- def get_integer_value(self):
- return int(self.value)
-
-
-class CharConst(GenericConst):
- type = i8
- signed = False
-
- def __init__(self, value):
- self.value = ord(value)
-
- def operand2(self):
- return '%d' % self.value
-
- def get_integer_value(self):
- return self.value
-
-
-class UniCharConst(GenericConst):
- type = i32
- signed = True
-
- def __init__(self, value):
- self.value = unicode(value)
-
- def operand2(self):
- return '%s' % self.value
-
- def get_integer_value(self):
- return int(self.value)
-
-
-class IntConst(GenericConst):
- type = i32
- signed = True
-
- def __init__(self, value):
- self.value = int(value)
-
- def operand2(self):
- return str(self.value)
-
- def get_integer_value(self):
- return self.value
-
-
-class UIntConst(GenericConst):
- type = u32
- signed = False
-
- def __init__(self, value):
- self.value = value
-
- def operand2(self):
- return str(self.value)
-
- def get_integer_value(self):
- return intmask(self.value)
-
-
-class FloatConst(GenericConst):
- type = f64
- signed = True
-
- def __init__(self, value):
- self.value = float(value)
-
- def operand2(self):
- return str(self.value)
-
- @specialize.arg(1)
- def revealconst(self, T):
- assert T is lltype.Float
- return self.value
-
-
-class AddrConst(GenConst):
- type = pi8
- signed = False
- addr = llmemory.NULL #have 'addr' even when not instantiated
-
- def __init__(self, addr):
- self.addr = addr
-
- def operand(self):
- return '%s %s' % (self.type, self.operand2())
-
- def operand2(self):
- addr = self.addr
- s = str(llmemory.cast_adr_to_int(addr))
- if s == '0':
- s = 'null'
- return s
-
- @specialize.arg(1)
- def revealconst(self, T):
- if T is llmemory.Address:
- return self.addr
- elif isinstance(T, lltype.Ptr):
- return llmemory.cast_adr_to_ptr(self.addr, T)
- elif T is lltype.Signed:
- return llmemory.cast_adr_to_int(self.addr)
- else:
- msg = 'XXX not implemented'
- logger.dump(msg)
- assert 0, msg
-
-
class Block(GenLabel):
def writecode(self, lines):
raise NotImplementedError
More information about the Pypy-commit
mailing list