sirit/src/op.h
2020-07-29 05:46:50 -03:00

64 lines
1.2 KiB
C++

/* This file is part of the sirit project.
* Copyright (c) 2019 sirit
* This software may be used and distributed according to the terms of the
* 3-Clause BSD License
*/
#pragma once
#include <cstddef>
#include <optional>
#include <vector>
#include "common_types.h"
#include "operand.h"
#include "sirit/sirit.h"
#include "stream.h"
namespace Sirit {
class Op final : public Operand {
public:
explicit Op(spv::Op opcode, std::optional<u32> id = {}, Id result_type = nullptr);
~Op() override;
void Fetch(Stream& stream) const override;
std::size_t GetWordCount() const noexcept override;
bool Equal(const Operand& other) const noexcept override;
void Write(Stream& stream) const;
void Sink(std::unique_ptr<Operand> operand);
void Add(const Literal& literal);
void Add(std::span<const Literal> literals);
void Add(const Operand* operand);
void Add(u32 integer);
void Add(s32 integer);
void Add(std::string string);
void Add(std::span<const Id> ids);
private:
u16 CalculateTotalWords() const noexcept;
spv::Op opcode;
Id result_type;
std::optional<u32> id;
std::vector<const Operand*> operands;
std::vector<std::unique_ptr<Operand>> operand_store;
};
} // namespace Sirit