Add another construtor for opt::ir::Instruction

This commit is contained in:
qining 2016-08-12 17:26:35 -04:00
parent 4987ae6549
commit c814911904
2 changed files with 23 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include "instruction.h" #include "instruction.h"
#include <cassert> #include <cassert>
#include <initializer_list>
#include "reflect.h" #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<Operand>& 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<uint32_t>{type_id_});
}
if (result_id_ != 0) {
operands_.emplace_back(spv_operand_type_t::SPV_OPERAND_TYPE_RESULT_ID,
std::initializer_list<uint32_t>{result_id_});
}
operands_.insert(operands_.end(), in_operands.begin(), in_operands.end());
}
Instruction::Instruction(Instruction&& that) Instruction::Instruction(Instruction&& that)
: opcode_(that.opcode_), : opcode_(that.opcode_),
type_id_(that.type_id_), type_id_(that.type_id_),

View File

@ -62,6 +62,9 @@ struct Operand {
Operand(spv_operand_type_t t, std::vector<uint32_t>&& w) Operand(spv_operand_type_t t, std::vector<uint32_t>&& w)
: type(t), words(std::move(w)) {} : type(t), words(std::move(w)) {}
Operand(spv_operand_type_t t, const std::vector<uint32_t>& w)
: type(t), words(w) {}
spv_operand_type_t type; // Type of this logical operand. spv_operand_type_t type; // Type of this logical operand.
std::vector<uint32_t> words; // Binary segments of this logical operand. std::vector<uint32_t> words; // Binary segments of this logical operand.
@ -85,6 +88,11 @@ class Instruction {
Instruction(const spv_parsed_instruction_t& inst, Instruction(const spv_parsed_instruction_t& inst,
std::vector<Instruction>&& dbg_line = {}); std::vector<Instruction>&& 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<Operand>& in_operands);
Instruction(const Instruction&) = default; Instruction(const Instruction&) = default;
Instruction& operator=(const Instruction&) = default; Instruction& operator=(const Instruction&) = default;