1#!/usr/bin/python3 2# 3# Copyright (C) 2023 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17"""Generate machine IR register class definitions from data file.""" 18 19def gen_machine_reg_class_inc(f, reg_classes): 20 for reg_class in reg_classes: 21 name = reg_class.get('name') 22 regs = reg_class.get('regs') 23 print('inline constexpr uint64_t k%sMask =' % (name), file=f) 24 for r in regs[: -1]: 25 print(' (1ULL << kMachineReg%s.reg()) |' % (r), file=f) 26 print(' (1ULL << kMachineReg%s.reg());' % (regs[-1]), file=f) 27 print('inline constexpr MachineRegClass k%s = {' % (name), file=f) 28 print(' "%s",' % (name), file=f) 29 print(' %d,' % (reg_class.get('size')), file=f) 30 print(' k%sMask,' % (name), file=f) 31 print(' %d,' % (len(regs)), file=f) 32 print(' {', file=f) 33 for r in regs: 34 print(' kMachineReg%s,' % (r), file=f) 35 print(' }', file=f) 36 print('};', file=f) 37 38 39def expand_aliases(reg_classes): 40 expanded = {} 41 for reg_class in reg_classes: 42 expanded_regs = [] 43 for r in reg_class.get('regs'): 44 expanded_regs.extend(expanded.get(r, [r])) 45 reg_class['regs'] = expanded_regs 46 expanded[reg_class.get('name')] = expanded_regs 47