Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / bl / api / pfe / src / Pfe_Slicer.py
# ========== Copyright Header Begin ==========================================
#
# OpenSPARC T2 Processor File: Pfe_Slicer.py
# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
#
# The above named program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License version 2 as published by the Free Software Foundation.
#
# The above named program is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this work; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ========== Copyright Header End ============================================
class Slicer:
"""
Slicer(list) takes a list as argument. When a Slicer
object is subscribted it returns a sublist of the list.
For example:
s = Slicer(range(0,64))
s[0] => [0]
s[0,2] => [0,2]
s[0:2] => [0,1]
s[0:2,4] => [0,1,4]
s[0:4:2] => [0,2,4]
s[0:2,4:6] => [0,1,4,5]
"""
def __init__(self,list):
self.list = list
def __getitem__(self,index):
if type(index) == tuple:
l = []
for i in index:
if type(i) == slice:
l.extend(self.list[i])
else:
l.append(self.list[i])
return l
elif type(index) == slice:
return self.list[index]
else:
return [self.list[index]]
if __name__ == '__main__':
s=Slicer(range(0,64))
print s[0]
print s[0:32]
print s[0,8,16,56,64]
print s[0:32:8]
print s[0:8,8:16]
print s[0:8,8:16,32,56:64]