• 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
31% def get_operand_kind(op, insn)
32%   if op.reg?
33%     if op.src? and op.dst?
34%       return "OperandKind::SRC_DST_VREG"
35%     elsif op.src?
36%       return "OperandKind::SRC_VREG"
37%     elsif op.dst?
38%       return "OperandKind::DST_VREG"
39%     end
40%     return nil
41%   elsif op.imm?
42%     is_jump = insn.properties.include? 'jump'
43%     return is_jump ? "OperandKind::LABEL" : "OperandKind::IMM"
44%  elsif op.id?
45%    is_string_id = insn.properties.include? 'string_id'
46%    return is_string_id ? "OperandKind::STRING_ID" : "OperandKind::ID"
47%  else
48%    return nil
49%  end
50% end
51%
52% def make_format(fmt, insn)
53%   operands = fmt.operands.map {|op| "{#{get_operand_kind(op, insn)}, #{op.width}}"}
54%   return operands
55% end
56%
57% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group|
58% insn = group.first
59% formats = group.map {|i| make_format(i,insn) }
60% empty = false
61% formats.each.with_index do |fmt, index|
62%   if fmt.length != 0
63constexpr std::array<const FormatItem, <%= fmt.length %>> <%= get_format_item_name(mnemonic, index) %> = {{
64  <%= fmt.join(", ") %>
65}};
66%   else
67%     empty = true
68%   end
69% end
70%
71%   if empty
72constexpr std::array<const Format, 0> <%= get_format_name(mnemonic) %>  = {{}};
73%   else
74constexpr std::array<const Format, <%= formats.length %>> <%= get_format_name(mnemonic) %> = {{
75% format_items = (0..(formats.length - 1)).map {|index| "{" + get_format_item_name(mnemonic, index) + ".data(), " +  get_format_item_name(mnemonic, index) + ".size()}" }
76  <%= format_items.join(", ") %>
77%
78}};
79%   end
80% end
81}  // namespace panda::es2panda::compiler
82
83#endif
84