-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathraddress.py
More file actions
144 lines (104 loc) · 4.92 KB
/
raddress.py
File metadata and controls
144 lines (104 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# rtyping of memory address operations
from rpython.rtyper.llannotation import SomeAddress, SomeTypedAddressAccess
from rpython.rlib.rarithmetic import r_uint
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.lltypesystem.llmemory import (NULL, Address,
cast_adr_to_int, fakeaddress, sizeof)
from rpython.rtyper.rmodel import Repr
from rpython.rtyper.rint import IntegerRepr
from rpython.rtyper.rptr import PtrRepr
from rpython.tool.pairtype import pairtype
class __extend__(SomeAddress):
def rtyper_makerepr(self, rtyper):
return address_repr
def rtyper_makekey(self):
return self.__class__,
class __extend__(SomeTypedAddressAccess):
def rtyper_makerepr(self, rtyper):
return TypedAddressAccessRepr(self.type)
def rtyper_makekey(self):
return self.__class__, self.type
class AddressRepr(Repr):
lowleveltype = Address
def convert_const(self, value):
# note that llarena.fakearenaaddress is not supported as a constant
# in graphs
assert type(value) is fakeaddress
return value
def ll_str(self, a):
from rpython.rtyper.lltypesystem.rstr import ll_str
id = ll_addrhash(a)
return ll_str.ll_int2hex(r_uint(id), True)
def rtype_getattr(self, hop):
v_access = hop.inputarg(address_repr, 0)
return v_access
def rtype_bool(self, hop):
v_addr, = hop.inputargs(address_repr)
c_null = hop.inputconst(address_repr, NULL)
return hop.genop('adr_ne', [v_addr, c_null],
resulttype=lltype.Bool)
def get_ll_eq_function(self):
return None
def get_ll_hash_function(self):
return ll_addrhash
get_ll_fasthash_function = get_ll_hash_function
def ll_addrhash(addr1):
return cast_adr_to_int(addr1, "forced")
address_repr = AddressRepr()
class TypedAddressAccessRepr(Repr):
lowleveltype = Address
def __init__(self, typ):
self.type = typ
class __extend__(pairtype(TypedAddressAccessRepr, IntegerRepr)):
def rtype_getitem((r_acc, r_int), hop):
v_addr, v_offs = hop.inputargs(hop.args_r[0], lltype.Signed)
c_size = hop.inputconst(lltype.Signed, sizeof(r_acc.type))
v_offs_mult = hop.genop('int_mul', [v_offs, c_size],
resulttype=lltype.Signed)
return hop.genop('raw_load', [v_addr, v_offs_mult],
resulttype = r_acc.type)
def rtype_setitem((r_acc, r_int), hop):
v_addr, v_offs, v_value = hop.inputargs(hop.args_r[0], lltype.Signed, r_acc.type)
c_size = hop.inputconst(lltype.Signed, sizeof(r_acc.type))
v_offs_mult = hop.genop('int_mul', [v_offs, c_size],
resulttype=lltype.Signed)
return hop.genop('raw_store', [v_addr, v_offs_mult, v_value])
class __extend__(pairtype(AddressRepr, IntegerRepr)):
def rtype_add((r_addr, r_int), hop):
if r_int.lowleveltype == lltype.Signed:
v_addr, v_offs = hop.inputargs(Address, lltype.Signed)
return hop.genop('adr_add', [v_addr, v_offs], resulttype=Address)
return NotImplemented
rtype_inplace_add = rtype_add
def rtype_sub((r_addr, r_int), hop):
if r_int.lowleveltype == lltype.Signed:
v_addr, v_offs = hop.inputargs(Address, lltype.Signed)
return hop.genop('adr_sub', [v_addr, v_offs], resulttype=Address)
return NotImplemented
rtype_inplace_sub = rtype_sub
class __extend__(pairtype(AddressRepr, AddressRepr)):
def rtype_sub((r_addr1, r_addr2), hop):
v_addr1, v_addr2 = hop.inputargs(Address, Address)
return hop.genop('adr_delta', [v_addr1, v_addr2], resulttype=lltype.Signed)
def rtype_eq((r_addr1, r_addr2), hop):
v_addr1, v_addr2 = hop.inputargs(Address, Address)
return hop.genop('adr_eq', [v_addr1, v_addr2], resulttype=lltype.Bool)
def rtype_ne((r_addr1, r_addr2), hop):
v_addr1, v_addr2 = hop.inputargs(Address, Address)
return hop.genop('adr_ne', [v_addr1, v_addr2], resulttype=lltype.Bool)
def rtype_lt((r_addr1, r_addr2), hop):
v_addr1, v_addr2 = hop.inputargs(Address, Address)
return hop.genop('adr_lt', [v_addr1, v_addr2], resulttype=lltype.Bool)
def rtype_le((r_addr1, r_addr2), hop):
v_addr1, v_addr2 = hop.inputargs(Address, Address)
return hop.genop('adr_le', [v_addr1, v_addr2], resulttype=lltype.Bool)
def rtype_gt((r_addr1, r_addr2), hop):
v_addr1, v_addr2 = hop.inputargs(Address, Address)
return hop.genop('adr_gt', [v_addr1, v_addr2], resulttype=lltype.Bool)
def rtype_ge((r_addr1, r_addr2), hop):
v_addr1, v_addr2 = hop.inputargs(Address, Address)
return hop.genop('adr_ge', [v_addr1, v_addr2], resulttype=lltype.Bool)
# conversions
class __extend__(pairtype(PtrRepr, AddressRepr)):
def convert_from_to((r_ptr, r_addr), v, llops):
return llops.genop('cast_ptr_to_adr', [v], resulttype=Address)