• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1% def get_format_name(mnemonic)
2%   return "#{mnemonic.gsub('.', '_').upcase}" + "_FORMATS"
3% end
4% def get_format_item_name(mnemonic, index)
5%   return "#{mnemonic.gsub('.', '_').upcase}" + "_FORMAT_ITEMS_" + index.to_s
6% end
7/**
8 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22// Autogenerated file -- DO NOT EDIT!
23
24#ifndef ES2PANDA_COMPILER_GEN_FORMATS_H
25#define ES2PANDA_COMPILER_GEN_FORMATS_H
26
27#include "ir/irnode.h"
28
29namespace panda::es2panda::compiler {
30% def get_operand_kind(op, insn)
31%   if op.reg?
32%     if op.src? and op.dst?
33%       return "OperandKind::SRC_DST_VREG"
34%     elsif op.src?
35%       return "OperandKind::SRC_VREG"
36%     elsif op.dst?
37%       return "OperandKind::DST_VREG"
38%     end
39%     return nil
40%   elsif op.imm?
41%     is_jump = insn.properties.include? 'jump'
42%     return is_jump ? "OperandKind::LABEL" : "OperandKind::IMM"
43%  elsif op.id?
44%    is_string_id = insn.properties.include? 'string_id'
45%    return is_string_id ? "OperandKind::STRING_ID" : "OperandKind::ID"
46%  elsif op.prof?
47%    return "OperandKind::IMM"
48%  else
49%    return nil
50%  end
51% end
52%
53% def make_format(fmt, insn)
54%   operands = fmt.operands.map {|op| "{#{get_operand_kind(op, insn)}, #{op.width}}"}
55%   return operands
56% end
57%
58% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group|
59% insn = group.first
60% formats = group.map {|i| make_format(i,insn) }
61% empty = false
62% formats.each.with_index do |fmt, index|
63%   if fmt.length != 0
64constexpr std::array<const FormatItem, <%= fmt.length %>> <%= get_format_item_name(mnemonic, index) %> = {{
65  <%= fmt.join(", ") %>
66}};
67%   else
68%     empty = true
69%   end
70% end
71%
72%   if empty
73constexpr std::array<const Format, 0> <%= get_format_name(mnemonic) %>  = {{}};
74%   else
75constexpr std::array<const Format, <%= formats.length %>> <%= get_format_name(mnemonic) %> = {{
76% format_items = (0..(formats.length - 1)).map {|index| "{" + get_format_item_name(mnemonic, index) + ".data(), " +  get_format_item_name(mnemonic, index) + ".size()}" }
77  <%= format_items.join(", ") %>
78%
79}};
80%   end
81% end
82}  // namespace panda::es2panda::compiler
83
84#endif
85