diff --git a/source/opt/instruction.cpp b/source/opt/instruction.cpp index 65fb5293..03031b4d 100644 --- a/source/opt/instruction.cpp +++ b/source/opt/instruction.cpp @@ -27,6 +27,7 @@ #include "instruction.h" #include +#include #include "reflect.h" @@ -50,6 +51,20 @@ Instruction::Instruction(const spv_parsed_instruction_t& inst, } } +Instruction::Instruction(SpvOp op, uint32_t ty_id, uint32_t res_id, + const std::vector& in_operands) + : opcode_(op), type_id_(ty_id), result_id_(res_id), operands_() { + if (type_id_ != 0) { + operands_.emplace_back(spv_operand_type_t::SPV_OPERAND_TYPE_TYPE_ID, + std::initializer_list{type_id_}); + } + if (result_id_ != 0) { + operands_.emplace_back(spv_operand_type_t::SPV_OPERAND_TYPE_RESULT_ID, + std::initializer_list{result_id_}); + } + operands_.insert(operands_.end(), in_operands.begin(), in_operands.end()); +} + Instruction::Instruction(Instruction&& that) : opcode_(that.opcode_), type_id_(that.type_id_), diff --git a/source/opt/instruction.h b/source/opt/instruction.h index 6c53f083..73ac828d 100644 --- a/source/opt/instruction.h +++ b/source/opt/instruction.h @@ -62,6 +62,9 @@ struct Operand { Operand(spv_operand_type_t t, std::vector&& w) : type(t), words(std::move(w)) {} + Operand(spv_operand_type_t t, const std::vector& w) + : type(t), words(w) {} + spv_operand_type_t type; // Type of this logical operand. std::vector words; // Binary segments of this logical operand. @@ -85,6 +88,11 @@ class Instruction { Instruction(const spv_parsed_instruction_t& inst, std::vector&& dbg_line = {}); + // Creates an instruction with the given opcode |op|, type id: |ty_id|, + // result id: |res_id| and input operands: |in_operands|. + Instruction(SpvOp op, uint32_t ty_id, uint32_t res_id, + const std::vector& in_operands); + Instruction(const Instruction&) = default; Instruction& operator=(const Instruction&) = default;