sirit/src/instructions/memory.cpp

73 lines
2.3 KiB
C++
Raw Normal View History

2018-10-18 09:27:17 +02:00
/* This file is part of the sirit project.
2019-07-14 23:48:59 +02:00
* Copyright (c) 2019 sirit
* This software may be used and distributed according to the terms of the
* 3-Clause BSD License
2018-10-18 09:27:17 +02:00
*/
2019-03-11 07:26:21 +01:00
#include <cassert>
2018-11-01 09:13:30 +01:00
#include "op.h"
2018-10-18 09:27:17 +02:00
#include "sirit/sirit.h"
namespace Sirit {
2019-03-11 07:26:21 +01:00
Id Module::OpVariable(Id result_type, spv::StorageClass storage_class, Id initializer) {
2018-11-01 09:13:30 +01:00
auto op{std::make_unique<Op>(spv::Op::OpVariable, bound++, result_type)};
op->Add(static_cast<u32>(storage_class));
2018-10-18 09:27:17 +02:00
if (initializer) {
op->Add(initializer);
}
2018-11-01 09:13:30 +01:00
return AddCode(std::move(op));
2018-10-18 09:27:17 +02:00
}
2019-03-11 07:26:21 +01:00
Id Module::OpLoad(Id result_type, Id pointer, std::optional<spv::MemoryAccessMask> memory_access) {
2018-11-01 09:13:30 +01:00
auto op{std::make_unique<Op>(spv::Op::OpLoad, bound++, result_type)};
2018-10-31 08:16:26 +01:00
op->Add(pointer);
if (memory_access) {
2018-11-01 09:13:30 +01:00
op->Add(static_cast<u32>(*memory_access));
2018-10-31 08:16:26 +01:00
}
2018-11-01 09:13:30 +01:00
return AddCode(std::move(op));
2018-10-31 08:16:26 +01:00
}
2019-03-11 07:26:21 +01:00
Id Module::OpStore(Id pointer, Id object, std::optional<spv::MemoryAccessMask> memory_access) {
2018-11-01 09:13:30 +01:00
auto op{std::make_unique<Op>(spv::Op::OpStore)};
2018-10-31 09:05:06 +01:00
op->Add(pointer);
op->Add(object);
if (memory_access) {
2018-11-01 09:13:30 +01:00
op->Add(static_cast<u32>(*memory_access));
2018-10-31 09:05:06 +01:00
}
2018-11-01 09:13:30 +01:00
return AddCode(std::move(op));
2018-10-31 09:05:06 +01:00
}
2019-03-11 07:26:21 +01:00
Id Module::OpAccessChain(Id result_type, Id base, const std::vector<Id>& indexes) {
2018-10-31 07:37:36 +01:00
assert(indexes.size() > 0);
2018-11-01 09:13:30 +01:00
auto op{std::make_unique<Op>(spv::Op::OpAccessChain, bound++, result_type)};
2018-10-31 07:37:36 +01:00
op->Add(base);
op->Add(indexes);
2018-11-01 09:13:30 +01:00
return AddCode(std::move(op));
2018-10-31 07:37:36 +01:00
}
2018-11-01 02:20:49 +01:00
Id Module::OpCompositeInsert(Id result_type, Id object, Id composite,
2018-11-04 00:41:03 +01:00
const std::vector<Literal>& indexes) {
2019-03-11 07:26:21 +01:00
auto op{std::make_unique<Op>(spv::Op::OpCompositeInsert, bound++, result_type)};
2018-10-31 09:05:06 +01:00
op->Add(object);
op->Add(composite);
op->Add(indexes);
2018-11-01 09:13:30 +01:00
return AddCode(std::move(op));
2018-10-31 09:05:06 +01:00
}
2019-03-11 07:26:21 +01:00
Id Module::OpCompositeExtract(Id result_type, Id composite, const std::vector<Literal>& indexes) {
auto op{std::make_unique<Op>(spv::Op::OpCompositeExtract, bound++, result_type)};
2018-11-04 00:41:03 +01:00
op->Add(composite);
op->Add(indexes);
return AddCode(std::move(op));
}
2018-11-04 06:38:13 +01:00
Id Module::OpCompositeConstruct(Id result_type, const std::vector<Id>& ids) {
assert(ids.size() >= 1);
2019-03-11 07:26:21 +01:00
auto op{std::make_unique<Op>(spv::Op::OpCompositeConstruct, bound++, result_type)};
2018-11-04 06:38:13 +01:00
op->Add(ids);
return AddCode(std::move(op));
}
2018-10-18 09:27:17 +02:00
} // namespace Sirit