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