1#!/usr/bin/env ruby 2# Copyright (c) 2021-2025 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 15$header = %{ 16/** 17* Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved. 18*/ 19 20// Autogenerated file -- DO NOT EDIT! 21 22#ifndef CROSS_VALUES_CROSS_VALUES_H 23#define CROSS_VALUES_CROSS_VALUES_H 24 25} 26 27Dir.glob("#{ARGV[1]}/*values_gen.h").each do |values_h| 28 $header += "#include \"generated_values/#{File.basename(values_h)}\"\n" 29end 30$header += "\n" 31$header += "#include <cstddef>\n" 32$header += "#include \"libpandabase/utils/arch.h\"\n" 33$header += "#include \"runtime/entrypoints/entrypoints.h\"\n\n" 34 35def generate(input_file, output_file) 36 data = File.read(input_file) 37 names = data.scan /DEFINE_VALUE\((\w+),/ 38 names.concat data.scan /DEFINE_VALUE_WITH_TYPE\((\w+), .*, ([\w\s]+)\)$/ 39 File.open(output_file, "w") do |file| 40 file.puts $header 41 file.puts "namespace ark::cross_values {" 42 43 names.sort_by(&:first).each do |define| 44 file.puts %< 45[[maybe_unused]] static constexpr #{define[1].nil? ? "ptrdiff_t" : define[1]} Get#{define[0].split('_').collect(&:capitalize).join}(Arch arch) 46{ 47 switch (arch) { 48> 49 Dir.glob("#{ARGV[1]}/*_values_gen.h").each do |values_h| 50 file.puts " case Arch::#{File.basename(values_h, "_values_gen.h")}:\n" 51 file.puts " return cross_values::#{File.basename(values_h, "_values_gen.h")}::#{define[0]}_VAL;\n" 52 end 53 file.puts " default:\n" 54 file.puts " LOG(FATAL, COMMON) << \"No cross-values generated for \" << GetStringFromArch(arch);\n" 55 file.puts " UNREACHABLE();\n" 56 file.puts " }\n" 57 file.puts "}\n" 58 end 59 60 file.puts %< 61// Specific getter for TLS entrypoints offsets: 62[[maybe_unused]] static constexpr ptrdiff_t GetManagedThreadEntrypointOffset(Arch arch, ark::EntrypointId id) 63{ 64 return GetManagedThreadEntrypointsOffset(arch) + static_cast<size_t>(id) * PointerSize(arch); 65} 66 67> 68 file.puts "} // namespace ark::cross_values" 69 file.puts 70 file.puts "#endif // CROSS_VALUES_CROSS_VALUES_H" 71 file.puts 72 end 73end 74 75abort "Failed: input file, generated values directory and output file required!" if ARGV.size < 3 76 77generate ARGV[0], ARGV[2] 78