from Pfe_Conversion
import *
#----------------------------------------------------------------------------
# Io is the wrapper that provides the hooks to all the ways to access
# io: 1,2,4,8 bytes, int or double, or little endian ...
#----------------------------------------------------------------------------
self
.b
= IoInterface(self
,self
.__ldb
__, self
.__stb
__,1)
self
.h
= IoInterface(self
,self
.__ldh
__, self
.__sth
__,2)
self
.w
= IoInterface(self
,self
.__ldw
__, self
.__stw
__,4)
self
.x
= IoInterface(self
,self
.__ldx
__ , self
.__stx
__,8)
self
.f
= IoInterface(self
,self
.__ldf
__, self
.__stf
__,4)
self
.d
= IoInterface(self
,self
.__ldd
__, self
.__std
__,8)
self
.c
= IoInterface(self
,self
.__ldc
__, self
.__stc
__,1)
self
.cl
= self
.c
# ha, simply for completeness
self
.bl
= self
.b
# ha, simply for completeness
self
.hl
= IoInterface(self
,self
.__ldhl
__, self
.__sthl
__,2)
self
.wl
= IoInterface(self
,self
.__ldwl
__, self
.__stwl
__,4)
self
.xl
= IoInterface(self
,self
.__ldxl
__, self
.__stxl
__,8)
self
.fl
= IoInterface(self
,self
.__ldfl
__, self
.__stfl
__,4)
self
.dl
= IoInterface(self
,self
.__lddl
__, self
.__stdl
__,8)
# __ldb__(), __ldh__(), __ldw__(), and __ldx__() implement 1, 2, 4 and
# 8 byte load operations. They need to be provided by the implementation.
def __ldb__(self
,sid
,addr
): pass
def __ldh__(self
,sid
,addr
): pass
def __ldw__(self
,sid
,addr
): pass
def __ldx__(self
,sid
,addr
): pass
# __stb__(), __sth__(), __stw__(), and __stx__() implement 1, 2, 4 and
# 8 byte store operations. They need to be provided by the implementation.
def __stb__(self
,sid
,addr
,data
): pass
def __sth__(self
,sid
,addr
,data
): pass
def __stw__(self
,sid
,addr
,data
): pass
def __stx__(self
,sid
,addr
,data
): pass
def __ldc__( self
,sid
,addr
): return chr(self
.__ldb
__(sid
,addr
))
def __ldf__( self
,sid
,addr
): return w2f(self
.__ldw
__(sid
,addr
))
def __ldd__( self
,sid
,addr
): return x2d(long(self
.__ldx
__(sid
,addr
)))
def __ldhl__(self
,sid
,addr
): return h2h(self
.__ldh
__(sid
,addr
))
def __ldwl__(self
,sid
,addr
): return w2w(self
.__ldw
__(sid
,addr
))
def __ldxl__(self
,sid
,addr
): return x2x(long(self
.__ldx
__(sid
,addr
)))
def __ldfl__(self
,sid
,addr
): return w2f(self
.__ldwl
__(sid
,addr
))
def __lddl__(self
,sid
,addr
): return x2d(self
.__ldxl
__(sid
,addr
))
def __stc__( self
,sid
,addr
,data
): self
.__stb
__(sid
,addr
,ord(data
))
def __stf__( self
,sid
,addr
,data
): self
.__stw
__(sid
,addr
,f2w(data
))
def __std__( self
,sid
,addr
,data
): self
.__stx
__(sid
,addr
,d2x(data
))
def __sthl__(self
,sid
,addr
,data
): self
.__sth
__(sid
,addr
,h2h(data
))
def __stwl__(self
,sid
,addr
,data
): self
.__stw
__(sid
,addr
,w2w(data
))
def __stxl__(self
,sid
,addr
,data
): self
.__stx
__(sid
,addr
,x2x(long(data
)))
def __stfl__(self
,sid
,addr
,data
): self
.__stwl
__(sid
,addr
,f2w(data
))
def __stdl__(self
,sid
,addr
,data
): self
.__stxl
__(sid
,addr
,d2x(data
))
#----------------------------------------------------------------------------
# IoInterface implements the actual index operator for
# the various io sizes, expliting pythons slicing operator
#----------------------------------------------------------------------------
def __init__(self
,io
,load
,store
,size
):
def slice_step(self
,__slice__
,step
):
if __slice__
.step
== None:
def __getitem__(self
,address
):
if type(address
) == slice:
s
= self
.slice_step(address
,self
.__size
__)
m
.append(self
.__ld
__(0,a
))
return self
.__ld
__(0,address
)
def __setitem__(self
,address
,value
):
if type(address
) == slice:
s
= self
.slice_step(address
,self
.__size
__)
while a
< address
.stop
and i
< len(value
):
self
.__st
__(0,a
,value
[i
])
self
.__st
__(0,address
,value
)