• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SRC_WRITER_SPIRV_INSTRUCTION_H_
16 #define SRC_WRITER_SPIRV_INSTRUCTION_H_
17 
18 #include <vector>
19 
20 #include "spirv/unified1/spirv.hpp11"
21 #include "src/writer/spirv/operand.h"
22 
23 namespace tint {
24 namespace writer {
25 namespace spirv {
26 
27 /// A single SPIR-V instruction
28 class Instruction {
29  public:
30   /// Constructor
31   /// @param op the op to generate
32   /// @param operands the operand values for the instruction
33   Instruction(spv::Op op, OperandList operands);
34   /// Copy Constructor
35   Instruction(const Instruction&);
36   ~Instruction();
37 
38   /// @returns the instructions op
opcode()39   spv::Op opcode() const { return op_; }
40 
41   /// @returns the instructions operands
operands()42   const OperandList& operands() const { return operands_; }
43 
44   /// @returns the number of uint32_t's needed to hold the instruction
45   uint32_t word_length() const;
46 
47  private:
48   spv::Op op_ = spv::Op::OpNop;
49   OperandList operands_;
50 };
51 
52 /// A list of instructions
53 using InstructionList = std::vector<Instruction>;
54 
55 }  // namespace spirv
56 }  // namespace writer
57 }  // namespace tint
58 
59 #endif  // SRC_WRITER_SPIRV_INSTRUCTION_H_
60