1
0
Fork 0
mirror of https://git.suyu.dev/suyu/sirit.git synced 2025-01-11 13:16:02 +00:00
sirit/src/insts/memory.cpp

63 lines
1.9 KiB
C++
Raw Normal View History

2018-10-18 08:27:17 +01:00
/* 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.
*/
2018-11-01 08:13:30 +00:00
#include "op.h"
2018-10-18 08:27:17 +01:00
#include "sirit/sirit.h"
2018-10-31 06:37:36 +00:00
#include <cassert>
2018-10-18 08:27:17 +01:00
namespace Sirit {
2018-11-01 01:20:49 +00:00
Id Module::OpVariable(Id result_type, spv::StorageClass storage_class,
Id initializer) {
2018-11-01 08:13:30 +00:00
auto op{std::make_unique<Op>(spv::Op::OpVariable, bound++, result_type)};
op->Add(static_cast<u32>(storage_class));
2018-10-18 08:27:17 +01:00
if (initializer) {
op->Add(initializer);
}
2018-11-01 08:13:30 +00:00
return AddCode(std::move(op));
2018-10-18 08:27:17 +01:00
}
2018-11-01 01:20:49 +00:00
Id Module::OpLoad(Id result_type, Id pointer,
std::optional<spv::MemoryAccessMask> memory_access) {
2018-11-01 08:13:30 +00:00
auto op{std::make_unique<Op>(spv::Op::OpLoad, bound++, result_type)};
2018-10-31 07:16:26 +00:00
op->Add(pointer);
if (memory_access) {
2018-11-01 08:13:30 +00:00
op->Add(static_cast<u32>(*memory_access));
2018-10-31 07:16:26 +00:00
}
2018-11-01 08:13:30 +00:00
return AddCode(std::move(op));
2018-10-31 07:16:26 +00:00
}
2018-11-01 01:20:49 +00:00
Id Module::OpStore(Id pointer, Id object,
std::optional<spv::MemoryAccessMask> memory_access) {
2018-11-01 08:13:30 +00:00
auto op{std::make_unique<Op>(spv::Op::OpStore)};
2018-10-31 08:05:06 +00:00
op->Add(pointer);
op->Add(object);
if (memory_access) {
2018-11-01 08:13:30 +00:00
op->Add(static_cast<u32>(*memory_access));
2018-10-31 08:05:06 +00:00
}
2018-11-01 08:13:30 +00:00
return AddCode(std::move(op));
2018-10-31 08:05:06 +00:00
}
2018-11-01 01:20:49 +00:00
Id Module::OpAccessChain(Id result_type, Id base,
const std::vector<Id>& indexes) {
2018-10-31 06:37:36 +00:00
assert(indexes.size() > 0);
2018-11-01 08:13:30 +00:00
auto op{std::make_unique<Op>(spv::Op::OpAccessChain, bound++, result_type)};
2018-10-31 06:37:36 +00:00
op->Add(base);
op->Add(indexes);
2018-11-01 08:13:30 +00:00
return AddCode(std::move(op));
2018-10-31 06:37:36 +00:00
}
2018-11-01 01:20:49 +00:00
Id Module::OpCompositeInsert(Id result_type, Id object, Id composite,
const std::vector<Literal>& indexes) {
2018-11-01 08:13:30 +00:00
auto op{std::make_unique<Op>(spv::Op::OpCompositeInsert, bound++, result_type)};
2018-10-31 08:05:06 +00:00
op->Add(object);
op->Add(composite);
op->Add(indexes);
2018-11-01 08:13:30 +00:00
return AddCode(std::move(op));
2018-10-31 08:05:06 +00:00
}
2018-10-18 08:27:17 +01:00
} // namespace Sirit