1#!/usr/bin/env ruby 2# Copyright (c) 2021-2024 Huawei Device Co., Ltd. 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 15module GeneratorTags 16 class Calculator 17 AVAILABLE_REGISTERS = %w[v5 v6 v7 v8] 18 PRIMITIVE_TAG = 0 19 OBJECT_TAG = 1 20 def refresh 21 @free_registers = AVAILABLE_REGISTERS.clone 22 end 23 24 def free_register 25 free_reg = @free_registers[0] 26 @free_registers.delete_at(0) 27 free_reg 28 end 29 30 def calculate_expected_tag(type) 31 val = PRIMITIVE_TAG 32 val = OBJECT_TAG if type.include?('ref') || type.include?('[]') 33 val 34 end 35 end 36end 37