2
from pypy.rlib.objectmodel import specialize
3
from pypy.rpython.lltypesystem import lltype, llmemory
4
from pypy.rlib.rarithmetic import intmask
5
from pypy.jit.codegen.model import GenVar, GenConst
6
from pypy.jit.codegen.llvm.logger import logger
7
from pypy.jit.codegen.llvm.compatibility import i1, i8, i16, i32, f64
20
label = 'L%d' % (self.n_labels,)
29
def __init__(self, type):
32
self.signed = type is i32 or type is f64
36
return '%s %s' % (self.type, self.operand2())
39
return '%%v%d' % (self.n,)
42
class GenericConst(GenConst):
45
return '%s %s' % (self.type, self.operand2())
48
def revealconst(self, T):
49
if isinstance(T, lltype.Ptr):
50
return lltype.cast_int_to_ptr(T, self.get_integer_value())
51
elif T is llmemory.Address:
52
return llmemory.cast_int_to_adr(self.get_integer_value())
54
return lltype.cast_primitive(T, self.get_integer_value())
57
class BoolConst(GenericConst):
61
def __init__(self, value):
62
self.value = bool(value)
70
def get_integer_value(self):
71
return int(self.value)
74
class CharConst(GenericConst):
78
def __init__(self, value):
79
self.value = ord(value)
82
return '%d' % self.value
84
def get_integer_value(self):
88
class UniCharConst(GenericConst):
92
def __init__(self, value):
93
self.value = unicode(value)
96
return '%s' % self.value
98
def get_integer_value(self):
99
return int(self.value)
102
class IntConst(GenericConst):
106
def __init__(self, value):
107
self.value = int(value)
110
return str(self.value)
112
def get_integer_value(self):
116
class UIntConst(GenericConst):
120
def __init__(self, value):
124
return str(self.value)
126
def get_integer_value(self):
127
return intmask(self.value)
130
class FloatConst(GenericConst):
134
def __init__(self, value):
135
self.value = float(value)
138
return str(self.value)
141
def revealconst(self, T):
142
assert T is lltype.Float
146
class AddrConst(GenConst):
149
addr = llmemory.NULL #have 'addr' even when not instantiated
151
def __init__(self, addr):
155
return '%s %s' % (self.type, self.operand2())
159
s = str(llmemory.cast_adr_to_int(addr))
165
def revealconst(self, T):
166
if T is llmemory.Address:
168
elif isinstance(T, lltype.Ptr):
169
return llmemory.cast_adr_to_ptr(self.addr, T)
170
elif T is lltype.Signed:
171
return llmemory.cast_adr_to_int(self.addr)
173
msg = 'XXX not implemented'