13af6ab5fSopenharmony_ci% def get_format_name(mnemonic)
23af6ab5fSopenharmony_ci%   return "#{mnemonic.gsub('.', '_').upcase}" + "_FORMATS"
33af6ab5fSopenharmony_ci% end
43af6ab5fSopenharmony_ci% def get_format_item_name(mnemonic, index)
53af6ab5fSopenharmony_ci%   return "#{mnemonic.gsub('.', '_').upcase}" + "_FORMAT_ITEMS_" + index.to_s
63af6ab5fSopenharmony_ci% end
73af6ab5fSopenharmony_ci/**
83af6ab5fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
93af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
103af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License.
113af6ab5fSopenharmony_ci * You may obtain a copy of the License at
123af6ab5fSopenharmony_ci *
133af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
143af6ab5fSopenharmony_ci *
153af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
163af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
173af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and
193af6ab5fSopenharmony_ci * limitations under the License.
203af6ab5fSopenharmony_ci */
213af6ab5fSopenharmony_ci
223af6ab5fSopenharmony_ci// Autogenerated file -- DO NOT EDIT!
233af6ab5fSopenharmony_ci
243af6ab5fSopenharmony_ci#ifndef ES2PANDA_COMPILER_GEN_FORMATS_H
253af6ab5fSopenharmony_ci#define ES2PANDA_COMPILER_GEN_FORMATS_H
263af6ab5fSopenharmony_ci
273af6ab5fSopenharmony_ci#include <ir/irnode.h>
283af6ab5fSopenharmony_ci
293af6ab5fSopenharmony_cinamespace panda::es2panda::compiler {
303af6ab5fSopenharmony_ci
313af6ab5fSopenharmony_ci% def get_operand_kind(op, insn)
323af6ab5fSopenharmony_ci%   if op.reg?
333af6ab5fSopenharmony_ci%     if op.src? and op.dst?
343af6ab5fSopenharmony_ci%       return "OperandKind::SRC_DST_VREG"
353af6ab5fSopenharmony_ci%     elsif op.src?
363af6ab5fSopenharmony_ci%       return "OperandKind::SRC_VREG"
373af6ab5fSopenharmony_ci%     elsif op.dst?
383af6ab5fSopenharmony_ci%       return "OperandKind::DST_VREG"
393af6ab5fSopenharmony_ci%     end
403af6ab5fSopenharmony_ci%     return nil
413af6ab5fSopenharmony_ci%   elsif op.imm?
423af6ab5fSopenharmony_ci%     is_jump = insn.properties.include? 'jump'
433af6ab5fSopenharmony_ci%     return is_jump ? "OperandKind::LABEL" : "OperandKind::IMM"
443af6ab5fSopenharmony_ci%  elsif op.id?
453af6ab5fSopenharmony_ci%    is_string_id = insn.properties.include? 'string_id'
463af6ab5fSopenharmony_ci%    return is_string_id ? "OperandKind::STRING_ID" : "OperandKind::ID"
473af6ab5fSopenharmony_ci%  else
483af6ab5fSopenharmony_ci%    return nil
493af6ab5fSopenharmony_ci%  end
503af6ab5fSopenharmony_ci% end
513af6ab5fSopenharmony_ci%
523af6ab5fSopenharmony_ci% def make_format(fmt, insn)
533af6ab5fSopenharmony_ci%   operands = fmt.operands.map {|op| "{#{get_operand_kind(op, insn)}, #{op.width}}"}
543af6ab5fSopenharmony_ci%   return operands
553af6ab5fSopenharmony_ci% end
563af6ab5fSopenharmony_ci%
573af6ab5fSopenharmony_ci% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group|
583af6ab5fSopenharmony_ci% insn = group.first
593af6ab5fSopenharmony_ci% formats = group.map {|i| make_format(i,insn) }
603af6ab5fSopenharmony_ci% empty = false
613af6ab5fSopenharmony_ci% formats.each.with_index do |fmt, index|
623af6ab5fSopenharmony_ci%   if fmt.length != 0
633af6ab5fSopenharmony_ciconstexpr std::array<const FormatItem, <%= fmt.length %>> <%= get_format_item_name(mnemonic, index) %> = {{
643af6ab5fSopenharmony_ci  <%= fmt.join(", ") %>
653af6ab5fSopenharmony_ci}};
663af6ab5fSopenharmony_ci%   else
673af6ab5fSopenharmony_ci%     empty = true
683af6ab5fSopenharmony_ci%   end
693af6ab5fSopenharmony_ci% end
703af6ab5fSopenharmony_ci%
713af6ab5fSopenharmony_ci%   if empty
723af6ab5fSopenharmony_ciconstexpr std::array<const Format, 0> <%= get_format_name(mnemonic) %>  = {{}};
733af6ab5fSopenharmony_ci%   else
743af6ab5fSopenharmony_ciconstexpr std::array<const Format, <%= formats.length %>> <%= get_format_name(mnemonic) %> = {{
753af6ab5fSopenharmony_ci% format_items = (0..(formats.length - 1)).map {|index| "{" + get_format_item_name(mnemonic, index) + ".data(), " +  get_format_item_name(mnemonic, index) + ".size()}" }
763af6ab5fSopenharmony_ci  <%= format_items.join(", ") %>
773af6ab5fSopenharmony_ci%
783af6ab5fSopenharmony_ci}};
793af6ab5fSopenharmony_ci%   end
803af6ab5fSopenharmony_ci% end
813af6ab5fSopenharmony_ci}  // namespace panda::es2panda::compiler
823af6ab5fSopenharmony_ci
833af6ab5fSopenharmony_ci#endif
84