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 15from common.immutables import ImmutableDict 16from common.logger import Logger 17from common.mixins import PrintableMixin 18 19class C1visualizerFile(PrintableMixin): 20 21 def __init__(self, fileName): 22 self.fileName = fileName 23 self.passes = [] 24 self.instructionSetFeatures = ImmutableDict() 25 26 def setISAFeatures(self, features): 27 self.instructionSetFeatures = ImmutableDict(features) 28 29 def addPass(self, new_pass): 30 self.passes.append(new_pass) 31 32 def findPass(self, name): 33 for entry in self.passes: 34 if entry.name == name: 35 return entry 36 return None 37 38 def __eq__(self, other): 39 return isinstance(other, self.__class__) \ 40 and self.passes == other.passes \ 41 and self.instructionSetFeatures == other.instructionSetFeatures 42 43 44class C1visualizerPass(PrintableMixin): 45 46 def __init__(self, parent, name, body, startLineNo): 47 self.parent = parent 48 self.name = name 49 self.body = body 50 self.startLineNo = startLineNo 51 52 if not self.name: 53 Logger.fail("C1visualizer pass does not have a name", self.fileName, self.startLineNo) 54 if not self.body: 55 Logger.fail("C1visualizer pass does not have a body", self.fileName, self.startLineNo) 56 57 self.parent.addPass(self) 58 59 @property 60 def fileName(self): 61 return self.parent.fileName 62 63 def __eq__(self, other): 64 return isinstance(other, self.__class__) \ 65 and self.name == other.name \ 66 and self.body == other.body 67