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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "insts.h"
|
|
|
|
#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-10-23 09:05:40 +01:00
|
|
|
auto op{new Op(spv::Op::OpVariable, bound++, result_type)};
|
2018-10-18 08:27:17 +01:00
|
|
|
AddEnum(op, storage_class);
|
|
|
|
if (initializer) {
|
|
|
|
op->Add(initializer);
|
|
|
|
}
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-11-01 01:20:49 +00:00
|
|
|
Id Module::OpLoad(Id result_type, Id pointer,
|
2018-11-01 00:22:00 +00:00
|
|
|
std::optional<spv::MemoryAccessMask> memory_access) {
|
2018-10-31 07:16:26 +00:00
|
|
|
auto op{new Op(spv::Op::OpLoad, bound++, result_type)};
|
|
|
|
op->Add(pointer);
|
|
|
|
if (memory_access) {
|
|
|
|
AddEnum(op, *memory_access);
|
|
|
|
}
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-11-01 01:20:49 +00:00
|
|
|
Id Module::OpStore(Id pointer, Id object,
|
2018-11-01 00:22:00 +00:00
|
|
|
std::optional<spv::MemoryAccessMask> memory_access) {
|
2018-10-31 08:05:06 +00:00
|
|
|
auto op{new Op(spv::Op::OpStore)};
|
|
|
|
op->Add(pointer);
|
|
|
|
op->Add(object);
|
|
|
|
if (memory_access) {
|
|
|
|
AddEnum(op, *memory_access);
|
|
|
|
}
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
auto op{new Op(spv::Op::OpAccessChain, bound++, result_type)};
|
|
|
|
op->Add(base);
|
|
|
|
op->Add(indexes);
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-11-01 01:20:49 +00:00
|
|
|
Id Module::OpCompositeInsert(Id result_type, Id object, Id composite,
|
2018-11-01 00:22:00 +00:00
|
|
|
const std::vector<Literal>& indexes) {
|
2018-10-31 08:05:06 +00:00
|
|
|
auto op{new Op(spv::Op::OpCompositeInsert, bound++, result_type)};
|
|
|
|
op->Add(object);
|
|
|
|
op->Add(composite);
|
|
|
|
op->Add(indexes);
|
|
|
|
return AddCode(op);
|
|
|
|
}
|
|
|
|
|
2018-10-18 08:27:17 +01:00
|
|
|
} // namespace Sirit
|