• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1% def get_node_kind(mnemonic)
2%   return "#{mnemonic.gsub('.', '_').upcase}"
3% end
4%
5% def get_format_name(mnemonic)
6%   return "#{mnemonic.gsub('.', '_').upcase}" + "_FORMATS"
7% end
8/**
9 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23// Autogenerated file -- DO NOT EDIT!
24
25#ifndef ES2PANDA_COMPILER_GEN_IR_ISA_H
26#define ES2PANDA_COMPILER_GEN_IR_ISA_H
27
28#include "ir/irnode.h"
29#include "generated/formats.h"
30#include "assembly-ins.h"
31
32namespace ark::es2panda::compiler {
33class Label : public IRNode {
34public:
35    explicit Label(const ir::AstNode* node, std::string id) : IRNode(node), id_(std::move(id)) {}
36
37    static constexpr std::string_view PREFIX = "LABEL_";
38
39    Formats GetFormats() const override
40    {
41        return Span<const Format>(nullptr, nullptr);
42    }
43
44    const std::string &Id() const
45    {
46        return id_;
47    }
48
49    size_t Registers([[maybe_unused]] std::array<VReg*, MAX_REG_OPERAND>* regs) override
50    {
51        return 0;
52    }
53
54    size_t Registers([[maybe_unused]] std::array<const VReg*, MAX_REG_OPERAND>* regs) const override
55    {
56        return 0;
57    }
58
59    size_t OutRegisters([[maybe_unused]] std::array<OutVReg, MAX_REG_OPERAND>* regs) const override
60    {
61        return 0;
62    }
63
64    void Transform(pandasm::Ins *ins, [[maybe_unused]] ProgramElement *programElement,
65                   [[maybe_unused]] uint32_t totalRegs) const override
66    {
67        ins->opcode = pandasm::Opcode::INVALID;
68        ins->setLabel = true;
69        ins->label = id_;
70    }
71
72private:
73    std::string id_;
74};
75
76// NOLINTBEGIN(readability-identifier-naming)
77% def insn2node(insn)
78%   mnemonic = insn.mnemonic.split('.')
79%   return mnemonic.map{|el| el == '64' ? 'Wide' : el.capitalize}.join()
80% end
81%
82% def get_ctor_args(insn)
83%     ops = Array.new
84%     ctor_args = Array.new
85%     op_map = Hash.new { |h, k| h[k] = [] }
86%
87%     insn.operands.map do |operand|
88%       name = operand.name
89%       param_name = name
90%       if operand.reg?
91%         param_name = "#{name}#{op_map['reg'].size}"
92%         op_map['reg'].push("#{param_name}_")
93%         op_map['dreg'].push(["#{param_name}_", operand.type]) if operand.dst?
94%         op_map['dreg'].push([nil, nil]) unless operand.dst?
95%         type = 'VReg'
96%       elsif operand.imm?
97%         if insn.jump?
98%           op_map['lbl'].push("#{name}_")
99%           type = 'Label*'
100%         else
101%           param_name = "#{name}#{op_map['imm'].size}"
102%           op_map['imm'].push("#{param_name}_")
103%           type = operand.type == 'f64' ? 'double' : operand.type == 'f32' ? 'float' : 'int64_t'
104%         end
105%       elsif operand.id?
106%         param_name = 'string_id'
107%         op_map['str'].push("#{param_name}_")
108%         type = 'util::StringView'
109%       end
110%       ops.push(param_name)
111%       ctor_args.push("#{type} #{param_name}")
112%     end
113%     return ops,ctor_args,op_map
114% end
115%
116% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group|
117% insn = group.first
118% node_kind = get_node_kind(mnemonic)
119% class_name = insn2node(insn)
120% base_class = "IRNode"
121% ops_list,ctor_arg_list,op_map = get_ctor_args(insn)
122% ctor_args = "const ir::AstNode* node" + (ctor_arg_list.length == 0 ? "" : ", ") + ctor_arg_list.map {|arg| "#{arg}"}.join(", ")
123% members = ctor_arg_list.map {|arg| "#{arg}_;"}.join("\n    ")
124% registers = op_map['reg'].map {|reg| "&#{reg}"}.join(", ")
125% ops = (ops_list.length == 0 ? "" : ", ") + ops_list.map { |op| "#{op}_(#{op})"}.join(", ")
126class <%= class_name %> : public <%= base_class %>
127{
128public:
129    explicit <%= class_name %>(<%= ctor_args %>) : <%= base_class %>(node)<%= ops %>
130    {
131% insn.operands.each do |operand|
132%   if operand.id? && operand.name != :string_id
133        ASSERT(!string_id.Empty());
134%   end
135% end
136    }
137
138    Formats GetFormats() const override
139    {
140        return Span<const Format>(<%= get_format_name(insn.mnemonic) %>);
141    }
142
143    size_t Registers([[maybe_unused]] std::array<VReg*, MAX_REG_OPERAND>* regs) override
144    {
145% reg_cnt = 0
146% for reg in op_map['reg']
147        (*regs)[<%= reg_cnt %>] = &<%= reg %>;
148%   reg_cnt+=1;
149% end
150        return <%= reg_cnt %>;
151    }
152
153    size_t Registers([[maybe_unused]] std::array<const VReg*, MAX_REG_OPERAND>* regs) const override
154    {
155% reg_cnt = 0
156% for reg in op_map['reg']
157        (*regs)[<%= reg_cnt %>] = &<%= reg %>;
158%   reg_cnt+=1;
159% end
160        return <%= reg_cnt %>;
161    }
162
163    size_t OutRegisters([[maybe_unused]] std::array<OutVReg, MAX_REG_OPERAND>* regs) const override
164    {
165% reg_cnt = 0
166%
167% def type_to_enum(type)
168%   return 'REF' if type == 'ref'
169%   return 'ANY' if type == 'any'
170%   return 'B64' if type == 'f64' || type == 'i64' || type == 'b64'
171%   return 'B32'
172% end
173% for reg, type in op_map['dreg']
174%   if reg
175        (*regs)[<%= reg_cnt %>] = {&<%= reg %>, OperandType::<%= type_to_enum(type) %>};
176%   elsif
177        (*regs)[<%= reg_cnt %>] = {nullptr, OperandType::NONE};
178%   end
179%   reg_cnt+=1;
180% end
181        return <%= reg_cnt %>;
182    }
183
184    void Transform(pandasm::Ins *ins, [[maybe_unused]] ProgramElement *programElement,
185                   [[maybe_unused]] uint32_t totalRegs) const override {
186      ins->opcode = pandasm::Opcode::<%= node_kind %>;
187% if op_map['reg'].length != 0
188      ins->regs.reserve(<%= op_map['reg'].length %>);
189% end
190% if op_map['imm'].length != 0
191      ins->imms.reserve(<%= op_map['imm'].length %>);
192% end
193% if op_map['str'].length + op_map['lbl'].length != 0
194      ins->ids.reserve(<%= op_map['str'].length + op_map['lbl'].length %>);
195% end
196% for reg in op_map['reg']
197      ins->regs.emplace_back(MapRegister(<%= reg %>.GetIndex(), totalRegs));
198% end
199% for imm in op_map['imm']
200      ins->imms.emplace_back(<%= imm %>);
201% end
202% if insn.properties.include? 'literalarray_id' and insn.properties.none? 'skip_literal_id_patch'
203      programElement->LiteralBufferIns().push_back(ins);
204%end
205% for str in op_map['str']
206      std::string <%= str %>mutf8 = <%= str %>.Mutf8();
207      ins->ids.emplace_back(<%= str %>mutf8);
208      programElement->Strings().insert(std::move(<%= str %>mutf8));
209% end
210% for lbl in op_map['lbl']
211      ins->ids.emplace_back(<%= lbl %>->Id());
212% end
213    }
214
215% if ops_list.length != 0
216private:
217    <%= members %>
218% end
219};
220
221% end
222// NOLINTEND(readability-identifier-naming)
223}  // namespace ark::es2panda::compiler
224
225#endif
226