• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env ruby
2# Copyright (c) 2021-2022 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
25namespace panda::cross_values::#{ARGV[2]} \{
26
27}
28
29def generate(input_file, output_file)
30  data = File.read(input_file)
31  defines = data.scan /"\^\^(\w+) [#\$]?([-+]?\d+)\^\^"/
32  output = ""
33  output += HEADER
34
35  defines.sort_by(&:first).each do |define|
36    output += "static constexpr ptrdiff_t #{define[0]}_VAL = #{define[1]};\n"
37  end
38  output +=  "}  // namespace panda::cross_values::#{ARGV[2]}\n\n"
39  output +=  "#endif  // CROSS_VALUES_GENERATED_VALUES_#{ARGV[2]}_VALUES_GEN_H\n"
40
41  File.open(output_file, "w") do |file|
42    file.write output
43  end
44end
45
46abort "Failed: input file, output file and arch-name required!" if ARGV.size < 3
47
48generate ARGV[0], ARGV[1]
49