Add OpDecorate

This commit is contained in:
ReinUsesLisp 2018-10-23 04:45:56 -03:00
parent 54cc7d06ce
commit 1458bd2c1c
6 changed files with 49 additions and 4 deletions

View file

@ -204,6 +204,12 @@ class Module {
Ref Variable(Ref result_type, spv::StorageClass storage_class, Ref Variable(Ref result_type, spv::StorageClass storage_class,
Ref initializer = nullptr); Ref initializer = nullptr);
// Annotation
/// Add a decoration to target.
Ref Decorate(Ref target, spv::Decoration decoration,
const std::vector<Operand*>& literals = {});
// Literals // Literals
static Operand* Literal(std::uint32_t value); static Operand* Literal(std::uint32_t value);
static Operand* Literal(std::uint64_t value); static Operand* Literal(std::uint64_t value);
@ -219,6 +225,8 @@ class Module {
Ref AddDeclaration(Op* op); Ref AddDeclaration(Op* op);
Ref AddAnnotation(Op* op);
std::uint32_t bound{1}; std::uint32_t bound{1};
std::set<spv::Capability> capabilities; std::set<spv::Capability> capabilities;

View file

@ -20,6 +20,7 @@ add_library(sirit
insts/flow.cpp insts/flow.cpp
insts/debug.cpp insts/debug.cpp
insts/memory.cpp insts/memory.cpp
insts/annotation.cpp
) )
target_include_directories(sirit target_include_directories(sirit
PUBLIC ../include PUBLIC ../include

21
src/insts/annotation.cpp Normal file
View file

@ -0,0 +1,21 @@
/* This file is part of the sirit project.
* Copyright (c) 2018 ReinUsesLisp
* This software may be used and distributed according to the terms of the GNU
* Lesser General Public License version 2.1 or any later version.
*/
#include "insts.h"
#include "sirit/sirit.h"
namespace Sirit {
Ref Module::Decorate(Ref target, spv::Decoration decoration,
const std::vector<Operand*>& literals) {
auto const op{new Op(spv::Op::OpDecorate)};
op->Add(target);
AddEnum(op, decoration);
op->Add(literals);
return AddAnnotation(op);
}
} // namespace Sirit

View file

@ -77,6 +77,12 @@ void Op::Add(const std::vector<Ref>& ids) {
} }
} }
void Op::Add(const std::vector<Operand*>& operands) {
for (Operand* operand : operands) {
Add(operand);
}
}
u16 Op::WordCount() const { u16 Op::WordCount() const {
u16 count{1}; u16 count{1};
if (result_type) { if (result_type) {

View file

@ -37,6 +37,8 @@ class Op : public Operand {
void Add(const std::vector<Ref>& ids); void Add(const std::vector<Ref>& ids);
void Add(const std::vector<Operand*>& operands);
private: private:
u16 WordCount() const; u16 WordCount() const;

View file

@ -55,7 +55,7 @@ std::vector<u8> Module::Assemble() const {
WriteSet(stream, entry_points); WriteSet(stream, entry_points);
// TODO write execution mode // TODO write execution mode
WriteSet(stream, debug); WriteSet(stream, debug);
// TODO write annotations WriteSet(stream, annotations);
WriteSet(stream, declarations); WriteSet(stream, declarations);
WriteSet(stream, global_variables); WriteSet(stream, global_variables);
WriteSet(stream, code); WriteSet(stream, code);
@ -99,6 +99,7 @@ Ref Module::AddGlobalVariable(Ref variable) {
} }
Ref Module::AddCode(Op* op) { Ref Module::AddCode(Op* op) {
assert(op);
code_store.push_back(std::unique_ptr<Op>(op)); code_store.push_back(std::unique_ptr<Op>(op));
return op; return op;
} }
@ -121,4 +122,10 @@ Ref Module::AddDeclaration(Op* op) {
} }
} }
Ref Module::AddAnnotation(Op* op) {
assert(op);
annotations.push_back(std::unique_ptr<Op>(op));
return op;
}
} // namespace Sirit } // namespace Sirit