13af6ab5fSopenharmony_ci% def get_node_kind(mnemonic)
23af6ab5fSopenharmony_ci%   return "#{mnemonic.gsub('.', '_').upcase}"
33af6ab5fSopenharmony_ci% end
43af6ab5fSopenharmony_ci%
53af6ab5fSopenharmony_ci% def get_format_name(mnemonic)
63af6ab5fSopenharmony_ci%   return "#{mnemonic.gsub('.', '_').upcase}" + "_FORMATS"
73af6ab5fSopenharmony_ci% end
83af6ab5fSopenharmony_ci/**
93af6ab5fSopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
103af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
113af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License.
123af6ab5fSopenharmony_ci * You may obtain a copy of the License at
133af6ab5fSopenharmony_ci *
143af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
153af6ab5fSopenharmony_ci *
163af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
173af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
183af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
193af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and
203af6ab5fSopenharmony_ci * limitations under the License.
213af6ab5fSopenharmony_ci */
223af6ab5fSopenharmony_ci
233af6ab5fSopenharmony_ci// Autogenerated file -- DO NOT EDIT!
243af6ab5fSopenharmony_ci
253af6ab5fSopenharmony_ci#ifndef ES2PANDA_COMPILER_GEN_IR_ISA_H
263af6ab5fSopenharmony_ci#define ES2PANDA_COMPILER_GEN_IR_ISA_H
273af6ab5fSopenharmony_ci
283af6ab5fSopenharmony_ci#include "ir/irnode.h"
293af6ab5fSopenharmony_ci#include "generated/formats.h"
303af6ab5fSopenharmony_ci#include "assembly-ins.h"
313af6ab5fSopenharmony_ci
323af6ab5fSopenharmony_cinamespace ark::es2panda::compiler {
333af6ab5fSopenharmony_ciclass Label : public IRNode {
343af6ab5fSopenharmony_cipublic:
353af6ab5fSopenharmony_ci    explicit Label(const ir::AstNode* node, std::string id) : IRNode(node), id_(std::move(id)) {}
363af6ab5fSopenharmony_ci
373af6ab5fSopenharmony_ci    static constexpr std::string_view PREFIX = "LABEL_";
383af6ab5fSopenharmony_ci
393af6ab5fSopenharmony_ci    Formats GetFormats() const override
403af6ab5fSopenharmony_ci    {
413af6ab5fSopenharmony_ci        return Span<const Format>(nullptr, nullptr);
423af6ab5fSopenharmony_ci    }
433af6ab5fSopenharmony_ci
443af6ab5fSopenharmony_ci    const std::string &Id() const
453af6ab5fSopenharmony_ci    {
463af6ab5fSopenharmony_ci        return id_;
473af6ab5fSopenharmony_ci    }
483af6ab5fSopenharmony_ci
493af6ab5fSopenharmony_ci    size_t Registers([[maybe_unused]] std::array<VReg*, MAX_REG_OPERAND>* regs) override
503af6ab5fSopenharmony_ci    {
513af6ab5fSopenharmony_ci        return 0;
523af6ab5fSopenharmony_ci    }
533af6ab5fSopenharmony_ci
543af6ab5fSopenharmony_ci    size_t Registers([[maybe_unused]] std::array<const VReg*, MAX_REG_OPERAND>* regs) const override
553af6ab5fSopenharmony_ci    {
563af6ab5fSopenharmony_ci        return 0;
573af6ab5fSopenharmony_ci    }
583af6ab5fSopenharmony_ci
593af6ab5fSopenharmony_ci    size_t OutRegisters([[maybe_unused]] std::array<OutVReg, MAX_REG_OPERAND>* regs) const override
603af6ab5fSopenharmony_ci    {
613af6ab5fSopenharmony_ci        return 0;
623af6ab5fSopenharmony_ci    }
633af6ab5fSopenharmony_ci
643af6ab5fSopenharmony_ci    void Transform(pandasm::Ins *ins, [[maybe_unused]] ProgramElement *programElement,
653af6ab5fSopenharmony_ci                   [[maybe_unused]] uint32_t totalRegs) const override
663af6ab5fSopenharmony_ci    {
673af6ab5fSopenharmony_ci        ins->opcode = pandasm::Opcode::INVALID;
683af6ab5fSopenharmony_ci        ins->setLabel = true;
693af6ab5fSopenharmony_ci        ins->label = id_;
703af6ab5fSopenharmony_ci    }
713af6ab5fSopenharmony_ci
723af6ab5fSopenharmony_ciprivate:
733af6ab5fSopenharmony_ci    std::string id_;
743af6ab5fSopenharmony_ci};
753af6ab5fSopenharmony_ci
763af6ab5fSopenharmony_ci// NOLINTBEGIN(readability-identifier-naming)
773af6ab5fSopenharmony_ci% def insn2node(insn)
783af6ab5fSopenharmony_ci%   mnemonic = insn.mnemonic.split('.')
793af6ab5fSopenharmony_ci%   return mnemonic.map{|el| el == '64' ? 'Wide' : el.capitalize}.join()
803af6ab5fSopenharmony_ci% end
813af6ab5fSopenharmony_ci%
823af6ab5fSopenharmony_ci% def get_ctor_args(insn)
833af6ab5fSopenharmony_ci%     ops = Array.new
843af6ab5fSopenharmony_ci%     ctor_args = Array.new
853af6ab5fSopenharmony_ci%     op_map = Hash.new { |h, k| h[k] = [] }
863af6ab5fSopenharmony_ci%
873af6ab5fSopenharmony_ci%     insn.operands.map do |operand|
883af6ab5fSopenharmony_ci%       name = operand.name
893af6ab5fSopenharmony_ci%       param_name = name
903af6ab5fSopenharmony_ci%       if operand.reg?
913af6ab5fSopenharmony_ci%         param_name = "#{name}#{op_map['reg'].size}"
923af6ab5fSopenharmony_ci%         op_map['reg'].push("#{param_name}_")
933af6ab5fSopenharmony_ci%         op_map['dreg'].push(["#{param_name}_", operand.type]) if operand.dst?
943af6ab5fSopenharmony_ci%         op_map['dreg'].push([nil, nil]) unless operand.dst?
953af6ab5fSopenharmony_ci%         type = 'VReg'
963af6ab5fSopenharmony_ci%       elsif operand.imm?
973af6ab5fSopenharmony_ci%         if insn.jump?
983af6ab5fSopenharmony_ci%           op_map['lbl'].push("#{name}_")
993af6ab5fSopenharmony_ci%           type = 'Label*'
1003af6ab5fSopenharmony_ci%         else
1013af6ab5fSopenharmony_ci%           param_name = "#{name}#{op_map['imm'].size}"
1023af6ab5fSopenharmony_ci%           op_map['imm'].push("#{param_name}_")
1033af6ab5fSopenharmony_ci%           type = operand.type == 'f64' ? 'double' : operand.type == 'f32' ? 'float' : 'int64_t'
1043af6ab5fSopenharmony_ci%         end
1053af6ab5fSopenharmony_ci%       elsif operand.id?
1063af6ab5fSopenharmony_ci%         param_name = 'string_id'
1073af6ab5fSopenharmony_ci%         op_map['str'].push("#{param_name}_")
1083af6ab5fSopenharmony_ci%         type = 'util::StringView'
1093af6ab5fSopenharmony_ci%       end
1103af6ab5fSopenharmony_ci%       ops.push(param_name)
1113af6ab5fSopenharmony_ci%       ctor_args.push("#{type} #{param_name}")
1123af6ab5fSopenharmony_ci%     end
1133af6ab5fSopenharmony_ci%     return ops,ctor_args,op_map
1143af6ab5fSopenharmony_ci% end
1153af6ab5fSopenharmony_ci%
1163af6ab5fSopenharmony_ci% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group|
1173af6ab5fSopenharmony_ci% insn = group.first
1183af6ab5fSopenharmony_ci% node_kind = get_node_kind(mnemonic)
1193af6ab5fSopenharmony_ci% class_name = insn2node(insn)
1203af6ab5fSopenharmony_ci% base_class = "IRNode"
1213af6ab5fSopenharmony_ci% ops_list,ctor_arg_list,op_map = get_ctor_args(insn)
1223af6ab5fSopenharmony_ci% ctor_args = "const ir::AstNode* node" + (ctor_arg_list.length == 0 ? "" : ", ") + ctor_arg_list.map {|arg| "#{arg}"}.join(", ")
1233af6ab5fSopenharmony_ci% members = ctor_arg_list.map {|arg| "#{arg}_;"}.join("\n    ")
1243af6ab5fSopenharmony_ci% registers = op_map['reg'].map {|reg| "&#{reg}"}.join(", ")
1253af6ab5fSopenharmony_ci% ops = (ops_list.length == 0 ? "" : ", ") + ops_list.map { |op| "#{op}_(#{op})"}.join(", ")
1263af6ab5fSopenharmony_ciclass <%= class_name %> : public <%= base_class %>
1273af6ab5fSopenharmony_ci{
1283af6ab5fSopenharmony_cipublic:
1293af6ab5fSopenharmony_ci    explicit <%= class_name %>(<%= ctor_args %>) : <%= base_class %>(node)<%= ops %>
1303af6ab5fSopenharmony_ci    {
1313af6ab5fSopenharmony_ci% insn.operands.each do |operand|
1323af6ab5fSopenharmony_ci%   if operand.id? && operand.name != :string_id
1333af6ab5fSopenharmony_ci        ASSERT(!string_id.Empty());
1343af6ab5fSopenharmony_ci%   end
1353af6ab5fSopenharmony_ci% end
1363af6ab5fSopenharmony_ci    }
1373af6ab5fSopenharmony_ci
1383af6ab5fSopenharmony_ci    Formats GetFormats() const override
1393af6ab5fSopenharmony_ci    {
1403af6ab5fSopenharmony_ci        return Span<const Format>(<%= get_format_name(insn.mnemonic) %>);
1413af6ab5fSopenharmony_ci    }
1423af6ab5fSopenharmony_ci
1433af6ab5fSopenharmony_ci    size_t Registers([[maybe_unused]] std::array<VReg*, MAX_REG_OPERAND>* regs) override
1443af6ab5fSopenharmony_ci    {
1453af6ab5fSopenharmony_ci% reg_cnt = 0
1463af6ab5fSopenharmony_ci% for reg in op_map['reg']
1473af6ab5fSopenharmony_ci        (*regs)[<%= reg_cnt %>] = &<%= reg %>;
1483af6ab5fSopenharmony_ci%   reg_cnt+=1;
1493af6ab5fSopenharmony_ci% end
1503af6ab5fSopenharmony_ci        return <%= reg_cnt %>;
1513af6ab5fSopenharmony_ci    }
1523af6ab5fSopenharmony_ci
1533af6ab5fSopenharmony_ci    size_t Registers([[maybe_unused]] std::array<const VReg*, MAX_REG_OPERAND>* regs) const override
1543af6ab5fSopenharmony_ci    {
1553af6ab5fSopenharmony_ci% reg_cnt = 0
1563af6ab5fSopenharmony_ci% for reg in op_map['reg']
1573af6ab5fSopenharmony_ci        (*regs)[<%= reg_cnt %>] = &<%= reg %>;
1583af6ab5fSopenharmony_ci%   reg_cnt+=1;
1593af6ab5fSopenharmony_ci% end
1603af6ab5fSopenharmony_ci        return <%= reg_cnt %>;
1613af6ab5fSopenharmony_ci    }
1623af6ab5fSopenharmony_ci
1633af6ab5fSopenharmony_ci    size_t OutRegisters([[maybe_unused]] std::array<OutVReg, MAX_REG_OPERAND>* regs) const override
1643af6ab5fSopenharmony_ci    {
1653af6ab5fSopenharmony_ci% reg_cnt = 0
1663af6ab5fSopenharmony_ci%
1673af6ab5fSopenharmony_ci% def type_to_enum(type)
1683af6ab5fSopenharmony_ci%   return 'REF' if type == 'ref'
1693af6ab5fSopenharmony_ci%   return 'ANY' if type == 'any'
1703af6ab5fSopenharmony_ci%   return 'B64' if type == 'f64' || type == 'i64' || type == 'b64'
1713af6ab5fSopenharmony_ci%   return 'B32'
1723af6ab5fSopenharmony_ci% end
1733af6ab5fSopenharmony_ci% for reg, type in op_map['dreg']
1743af6ab5fSopenharmony_ci%   if reg
1753af6ab5fSopenharmony_ci        (*regs)[<%= reg_cnt %>] = {&<%= reg %>, OperandType::<%= type_to_enum(type) %>};
1763af6ab5fSopenharmony_ci%   elsif
1773af6ab5fSopenharmony_ci        (*regs)[<%= reg_cnt %>] = {nullptr, OperandType::NONE};
1783af6ab5fSopenharmony_ci%   end
1793af6ab5fSopenharmony_ci%   reg_cnt+=1;
1803af6ab5fSopenharmony_ci% end
1813af6ab5fSopenharmony_ci        return <%= reg_cnt %>;
1823af6ab5fSopenharmony_ci    }
1833af6ab5fSopenharmony_ci
1843af6ab5fSopenharmony_ci    void Transform(pandasm::Ins *ins, [[maybe_unused]] ProgramElement *programElement,
1853af6ab5fSopenharmony_ci                   [[maybe_unused]] uint32_t totalRegs) const override {
1863af6ab5fSopenharmony_ci      ins->opcode = pandasm::Opcode::<%= node_kind %>;
1873af6ab5fSopenharmony_ci% if op_map['reg'].length != 0
1883af6ab5fSopenharmony_ci      ins->regs.reserve(<%= op_map['reg'].length %>);
1893af6ab5fSopenharmony_ci% end
1903af6ab5fSopenharmony_ci% if op_map['imm'].length != 0
1913af6ab5fSopenharmony_ci      ins->imms.reserve(<%= op_map['imm'].length %>);
1923af6ab5fSopenharmony_ci% end
1933af6ab5fSopenharmony_ci% if op_map['str'].length + op_map['lbl'].length != 0
1943af6ab5fSopenharmony_ci      ins->ids.reserve(<%= op_map['str'].length + op_map['lbl'].length %>);
1953af6ab5fSopenharmony_ci% end
1963af6ab5fSopenharmony_ci% for reg in op_map['reg']
1973af6ab5fSopenharmony_ci      ins->regs.emplace_back(MapRegister(<%= reg %>.GetIndex(), totalRegs));
1983af6ab5fSopenharmony_ci% end
1993af6ab5fSopenharmony_ci% for imm in op_map['imm']
2003af6ab5fSopenharmony_ci      ins->imms.emplace_back(<%= imm %>);
2013af6ab5fSopenharmony_ci% end
2023af6ab5fSopenharmony_ci% if insn.properties.include? 'literalarray_id' and insn.properties.none? 'skip_literal_id_patch'
2033af6ab5fSopenharmony_ci      programElement->LiteralBufferIns().push_back(ins);
2043af6ab5fSopenharmony_ci%end
2053af6ab5fSopenharmony_ci% for str in op_map['str']
2063af6ab5fSopenharmony_ci      std::string <%= str %>mutf8 = <%= str %>.Mutf8();
2073af6ab5fSopenharmony_ci      ins->ids.emplace_back(<%= str %>mutf8);
2083af6ab5fSopenharmony_ci      programElement->Strings().insert(std::move(<%= str %>mutf8));
2093af6ab5fSopenharmony_ci% end
2103af6ab5fSopenharmony_ci% for lbl in op_map['lbl']
2113af6ab5fSopenharmony_ci      ins->ids.emplace_back(<%= lbl %>->Id());
2123af6ab5fSopenharmony_ci% end
2133af6ab5fSopenharmony_ci    }
2143af6ab5fSopenharmony_ci
2153af6ab5fSopenharmony_ci% if ops_list.length != 0
2163af6ab5fSopenharmony_ciprivate:
2173af6ab5fSopenharmony_ci    <%= members %>
2183af6ab5fSopenharmony_ci% end
2193af6ab5fSopenharmony_ci};
2203af6ab5fSopenharmony_ci
2213af6ab5fSopenharmony_ci% end
2223af6ab5fSopenharmony_ci// NOLINTEND(readability-identifier-naming)
2233af6ab5fSopenharmony_ci}  // namespace ark::es2panda::compiler
2243af6ab5fSopenharmony_ci
2253af6ab5fSopenharmony_ci#endif
226