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