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 15HEADER = %{ 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_GENERATED_VALUES_#{ARGV[2]}_VALUES_GEN_H 23#define CROSS_VALUES_GENERATED_VALUES_#{ARGV[2]}_VALUES_GEN_H 24 25// NOLINTNEXTLINE(readability-identifier-naming) 26namespace ark::cross_values::#{ARGV[2]} \{ 27 28} 29 30def generate(input_file, output_file) 31 data = File.read(input_file) 32 defines = data.scan /"\^\^(\w+) [#\$]?([-+]?\d+)\s*([\w\s]*)\^\^"/ 33 output = "" 34 output += HEADER 35 36 defines.sort_by(&:first).each do |define| 37 output += "static constexpr #{define[2].empty? ? "ptrdiff_t" : define[2]} #{define[0]}_VAL = #{define[1]};\n" 38 end 39 output += "} // namespace ark::cross_values::#{ARGV[2]}\n\n" 40 output += "#endif // CROSS_VALUES_GENERATED_VALUES_#{ARGV[2]}_VALUES_GEN_H\n" 41 42 File.open(output_file, "w") do |file| 43 file.write output 44 end 45end 46 47abort "Failed: input file, output file and arch-name required!" if ARGV.size < 3 48 49generate ARGV[0], ARGV[1] 50