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-2024 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 ark::es2panda::compiler {
303af6ab5fSopenharmony_ci% def get_operand_kind(op, insn)
313af6ab5fSopenharmony_ci%   if op.reg?
323af6ab5fSopenharmony_ci%     if op.src? and op.dst?
333af6ab5fSopenharmony_ci%       return "OperandKind::SRC_DST_VREG"
343af6ab5fSopenharmony_ci%     elsif op.src?
353af6ab5fSopenharmony_ci%       return "OperandKind::SRC_VREG"
363af6ab5fSopenharmony_ci%     elsif op.dst?
373af6ab5fSopenharmony_ci%       return "OperandKind::DST_VREG"
383af6ab5fSopenharmony_ci%     end
393af6ab5fSopenharmony_ci%     return nil
403af6ab5fSopenharmony_ci%   elsif op.imm?
413af6ab5fSopenharmony_ci%     is_jump = insn.properties.include? 'jump'
423af6ab5fSopenharmony_ci%     return is_jump ? "OperandKind::LABEL" : "OperandKind::IMM"
433af6ab5fSopenharmony_ci%  elsif op.id?
443af6ab5fSopenharmony_ci%    is_string_id = insn.properties.include? 'string_id'
453af6ab5fSopenharmony_ci%    return is_string_id ? "OperandKind::STRING_ID" : "OperandKind::ID"
463af6ab5fSopenharmony_ci%  elsif op.prof?
473af6ab5fSopenharmony_ci%    return "OperandKind::IMM"
483af6ab5fSopenharmony_ci%  else
493af6ab5fSopenharmony_ci%    return nil
503af6ab5fSopenharmony_ci%  end
513af6ab5fSopenharmony_ci% end
523af6ab5fSopenharmony_ci%
533af6ab5fSopenharmony_ci% def make_format(fmt, insn)
543af6ab5fSopenharmony_ci%   operands = fmt.operands.map {|op| "{#{get_operand_kind(op, insn)}, #{op.width}}"}
553af6ab5fSopenharmony_ci%   return operands
563af6ab5fSopenharmony_ci% end
573af6ab5fSopenharmony_ci%
583af6ab5fSopenharmony_ci% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group|
593af6ab5fSopenharmony_ci% insn = group.first
603af6ab5fSopenharmony_ci% formats = group.map {|i| make_format(i,insn) }
613af6ab5fSopenharmony_ci% empty = false
623af6ab5fSopenharmony_ci% formats.each.with_index do |fmt, index|
633af6ab5fSopenharmony_ci%   if fmt.length != 0
643af6ab5fSopenharmony_ciconstexpr std::array<const FormatItem, <%= fmt.length %>> <%= get_format_item_name(mnemonic, index) %> = {{
653af6ab5fSopenharmony_ci  <%= fmt.join(", ") %>
663af6ab5fSopenharmony_ci}};
673af6ab5fSopenharmony_ci%   else
683af6ab5fSopenharmony_ci%     empty = true
693af6ab5fSopenharmony_ci%   end
703af6ab5fSopenharmony_ci% end
713af6ab5fSopenharmony_ci%
723af6ab5fSopenharmony_ci%   if empty
733af6ab5fSopenharmony_ciconstexpr std::array<const Format, 0> <%= get_format_name(mnemonic) %>  = {{}};
743af6ab5fSopenharmony_ci%   else
753af6ab5fSopenharmony_ciconstexpr std::array<const Format, <%= formats.length %>> <%= get_format_name(mnemonic) %> = {{
763af6ab5fSopenharmony_ci% format_items = (0..(formats.length - 1)).map {|index| "{" + get_format_item_name(mnemonic, index) + ".data(), " +  get_format_item_name(mnemonic, index) + ".size()}" }
773af6ab5fSopenharmony_ci  <%= format_items.join(", ") %>
783af6ab5fSopenharmony_ci%
793af6ab5fSopenharmony_ci}};
803af6ab5fSopenharmony_ci%   end
813af6ab5fSopenharmony_ci% end
823af6ab5fSopenharmony_ci}  // namespace ark::es2panda::compiler
833af6ab5fSopenharmony_ci
843af6ab5fSopenharmony_ci#endif
85