% def get_format_name(mnemonic) % return "#{mnemonic.gsub('.', '_').upcase}" + "_FORMATS" % end % def get_format_item_name(mnemonic, index) % return "#{mnemonic.gsub('.', '_').upcase}" + "_FORMAT_ITEMS_" + index.to_s % end /** * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Autogenerated file -- DO NOT EDIT! #ifndef ES2PANDA_COMPILER_GEN_FORMATS_H #define ES2PANDA_COMPILER_GEN_FORMATS_H #include namespace panda::es2panda::compiler { % def get_operand_kind(op, insn) % if op.reg? % if op.src? and op.dst? % return "OperandKind::SRC_DST_VREG" % elsif op.src? % return "OperandKind::SRC_VREG" % elsif op.dst? % return "OperandKind::DST_VREG" % end % return nil % elsif op.imm? % is_jump = insn.properties.include? 'jump' % return is_jump ? "OperandKind::LABEL" : "OperandKind::IMM" % elsif op.id? % is_string_id = insn.properties.include? 'string_id' % return is_string_id ? "OperandKind::STRING_ID" : "OperandKind::ID" % else % return nil % end % end % % def make_format(fmt, insn) % operands = fmt.operands.map {|op| "{#{get_operand_kind(op, insn)}, #{op.width}}"} % return operands % end % % Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group| % insn = group.first % formats = group.map {|i| make_format(i,insn) } % empty = false % formats.each.with_index do |fmt, index| % if fmt.length != 0 constexpr std::array> <%= get_format_item_name(mnemonic, index) %> = {{ <%= fmt.join(", ") %> }}; % else % empty = true % end % end % % if empty constexpr std::array <%= get_format_name(mnemonic) %> = {{}}; % else constexpr std::array> <%= get_format_name(mnemonic) %> = {{ % format_items = (0..(formats.length - 1)).map {|index| "{" + get_format_item_name(mnemonic, index) + ".data(), " + get_format_item_name(mnemonic, index) + ".size()}" } <%= format_items.join(", ") %> % }}; % end % end } // namespace panda::es2panda::compiler #endif