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 self.read_barrier_type = "none" 29 30 def set_isa_features(self, features): 31 self.instruction_set_features = ImmutableDict(features) 32 33 def set_read_barrier_type(self, read_barrier_type): 34 self.read_barrier_type = read_barrier_type 35 36 def add_pass(self, new_pass): 37 self.passes.append(new_pass) 38 39 def find_pass(self, name): 40 for entry in self.passes: 41 if entry.name == name: 42 return entry 43 return None 44 45 def __eq__(self, other): 46 return (isinstance(other, self.__class__) 47 and self.passes == other.passes 48 and self.instruction_set_features == other.instruction_set_features 49 and self.read_barrier_type == other.read_barrier_type) 50 51 52class C1visualizerPass(PrintableMixin): 53 def __init__(self, parent, name, body, start_line_no): 54 self.parent = parent 55 self.name = name 56 self.body = body 57 self.start_line_no = start_line_no 58 59 if not self.name: 60 Logger.fail("C1visualizer pass does not have a name", self.filename, self.start_line_no) 61 if not self.body: 62 Logger.fail("C1visualizer pass does not have a body", self.filename, self.start_line_no) 63 64 self.parent.add_pass(self) 65 66 @property 67 def filename(self): 68 return self.parent.base_file_name 69 70 def __eq__(self, other): 71 return (isinstance(other, self.__class__) 72 and self.name == other.name 73 and self.body == other.body) 74