proxy.py (12798:d9fc94b42670) | proxy.py (13663:9b64aeabf9a5) |
---|---|
1# Copyright (c) 2018 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 52 unchanged lines hidden (view full) --- 61 elif not self._search_self and self._search_up: 62 s = 'Parent' 63 else: 64 s = 'ConfusedProxy' 65 return s + '.' + self.path() 66 67 def __setattr__(self, attr, value): 68 if not attr.startswith('_'): | 1# Copyright (c) 2018 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 52 unchanged lines hidden (view full) --- 61 elif not self._search_self and self._search_up: 62 s = 'Parent' 63 else: 64 s = 'ConfusedProxy' 65 return s + '.' + self.path() 66 67 def __setattr__(self, attr, value): 68 if not attr.startswith('_'): |
69 raise AttributeError, \ 70 "cannot set attribute '%s' on proxy object" % attr | 69 raise AttributeError( 70 "cannot set attribute '%s' on proxy object" % attr) |
71 super(BaseProxy, self).__setattr__(attr, value) 72 73 # support for multiplying proxies by constants or other proxies to 74 # other params 75 def __mul__(self, other): 76 if not (isinstance(other, (int, long, float)) or isproxy(other)): | 71 super(BaseProxy, self).__setattr__(attr, value) 72 73 # support for multiplying proxies by constants or other proxies to 74 # other params 75 def __mul__(self, other): 76 if not (isinstance(other, (int, long, float)) or isproxy(other)): |
77 raise TypeError, \ 78 "Proxy multiplier must be a constant or a proxy to a param" | 77 raise TypeError( 78 "Proxy multiplier must be a constant or a proxy to a param") |
79 self._multipliers.append(other) 80 return self 81 82 __rmul__ = __mul__ 83 84 def _mulcheck(self, result, base): 85 for multiplier in self._multipliers: 86 if isproxy(multiplier): 87 multiplier = multiplier.unproxy(base) 88 # assert that we are multiplying with a compatible 89 # param 90 if not isinstance(multiplier, params.NumericParamValue): | 79 self._multipliers.append(other) 80 return self 81 82 __rmul__ = __mul__ 83 84 def _mulcheck(self, result, base): 85 for multiplier in self._multipliers: 86 if isproxy(multiplier): 87 multiplier = multiplier.unproxy(base) 88 # assert that we are multiplying with a compatible 89 # param 90 if not isinstance(multiplier, params.NumericParamValue): |
91 raise TypeError, \ 92 "Proxy multiplier must be a numerical param" | 91 raise TypeError( 92 "Proxy multiplier must be a numerical param") |
93 multiplier = multiplier.getValue() 94 result *= multiplier 95 return result 96 97 def unproxy(self, base): 98 obj = base 99 done = False 100 --- 10 unchanged lines hidden (view full) --- 111 if not obj: 112 break 113 result, done = self.find(obj) 114 115 self._visited = False 116 base._visited = False 117 118 if not done: | 93 multiplier = multiplier.getValue() 94 result *= multiplier 95 return result 96 97 def unproxy(self, base): 98 obj = base 99 done = False 100 --- 10 unchanged lines hidden (view full) --- 111 if not obj: 112 break 113 result, done = self.find(obj) 114 115 self._visited = False 116 base._visited = False 117 118 if not done: |
119 raise AttributeError, \ 120 "Can't resolve proxy '%s' of type '%s' from '%s'" % \ 121 (self.path(), self._pdesc.ptype_str, base.path()) | 119 raise AttributeError( 120 "Can't resolve proxy '%s' of type '%s' from '%s'" % \ 121 (self.path(), self._pdesc.ptype_str, base.path())) |
122 123 if isinstance(result, BaseProxy): 124 if result == self: | 122 123 if isinstance(result, BaseProxy): 124 if result == self: |
125 raise RuntimeError, "Cycle in unproxy" | 125 raise RuntimeError("Cycle in unproxy") |
126 result = result.unproxy(obj) 127 128 return self._mulcheck(result, base) 129 130 def getindex(obj, index): 131 if index == None: 132 return obj 133 try: --- 18 unchanged lines hidden (view full) --- 152 self._attr = attr 153 self._modifiers = [] 154 155 def __getattr__(self, attr): 156 # python uses __bases__ internally for inheritance 157 if attr.startswith('_'): 158 return super(AttrProxy, self).__getattr__(self, attr) 159 if hasattr(self, '_pdesc'): | 126 result = result.unproxy(obj) 127 128 return self._mulcheck(result, base) 129 130 def getindex(obj, index): 131 if index == None: 132 return obj 133 try: --- 18 unchanged lines hidden (view full) --- 152 self._attr = attr 153 self._modifiers = [] 154 155 def __getattr__(self, attr): 156 # python uses __bases__ internally for inheritance 157 if attr.startswith('_'): 158 return super(AttrProxy, self).__getattr__(self, attr) 159 if hasattr(self, '_pdesc'): |
160 raise AttributeError, "Attribute reference on bound proxy" | 160 raise AttributeError("Attribute reference on bound proxy") |
161 # Return a copy of self rather than modifying self in place 162 # since self could be an indirect reference via a variable or 163 # parameter 164 new_self = copy.deepcopy(self) 165 new_self._modifiers.append(attr) 166 return new_self 167 168 # support indexing on proxies (e.g., Self.cpu[0]) 169 def __getitem__(self, key): 170 if not isinstance(key, int): | 161 # Return a copy of self rather than modifying self in place 162 # since self could be an indirect reference via a variable or 163 # parameter 164 new_self = copy.deepcopy(self) 165 new_self._modifiers.append(attr) 166 return new_self 167 168 # support indexing on proxies (e.g., Self.cpu[0]) 169 def __getitem__(self, key): 170 if not isinstance(key, int): |
171 raise TypeError, "Proxy object requires integer index" | 171 raise TypeError("Proxy object requires integer index") |
172 if hasattr(self, '_pdesc'): | 172 if hasattr(self, '_pdesc'): |
173 raise AttributeError, "Index operation on bound proxy" | 173 raise AttributeError("Index operation on bound proxy") |
174 new_self = copy.deepcopy(self) 175 new_self._modifiers.append(key) 176 return new_self 177 178 def find(self, obj): 179 try: 180 val = getattr(obj, self._attr) 181 visited = False --- 85 unchanged lines hidden --- | 174 new_self = copy.deepcopy(self) 175 new_self._modifiers.append(key) 176 return new_self 177 178 def find(self, obj): 179 try: 180 val = getattr(obj, self._attr) 181 visited = False --- 85 unchanged lines hidden --- |