David Brazdil | 2c27f2c | 2015-05-12 18:06:38 +0100 | [diff] [blame] | 1 | # Copyright (C) 2014 The Android Open Source Project |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | from common.logger import Logger |
| 16 | from common.mixins import PrintableMixin |
| 17 | |
| 18 | class C1visualizerFile(PrintableMixin): |
| 19 | |
| 20 | def __init__(self, fileName): |
| 21 | self.fileName = fileName |
| 22 | self.passes = [] |
| 23 | |
| 24 | def addPass(self, new_pass): |
| 25 | self.passes.append(new_pass) |
| 26 | |
| 27 | def findPass(self, name): |
| 28 | for entry in self.passes: |
| 29 | if entry.name == name: |
| 30 | return entry |
| 31 | return None |
| 32 | |
| 33 | def __eq__(self, other): |
| 34 | return isinstance(other, self.__class__) \ |
| 35 | and self.passes == other.passes |
| 36 | |
| 37 | |
| 38 | class C1visualizerPass(PrintableMixin): |
| 39 | |
| 40 | def __init__(self, parent, name, body, startLineNo): |
| 41 | self.parent = parent |
| 42 | self.name = name |
| 43 | self.body = body |
| 44 | self.startLineNo = startLineNo |
| 45 | |
| 46 | if not self.name: |
| 47 | Logger.fail("C1visualizer pass does not have a name", self.fileName, self.startLineNo) |
| 48 | if not self.body: |
| 49 | Logger.fail("C1visualizer pass does not have a body", self.fileName, self.startLineNo) |
| 50 | |
| 51 | self.parent.addPass(self) |
| 52 | |
| 53 | @property |
| 54 | def fileName(self): |
| 55 | return self.parent.fileName |
| 56 | |
| 57 | def __eq__(self, other): |
| 58 | return isinstance(other, self.__class__) \ |
| 59 | and self.name == other.name \ |
| 60 | and self.body == other.body |